Commit eee6fa1e authored by Michael Natterer's avatar Michael Natterer 😴

libgimpcolor: start adding profile utility functions to gimplcms.[ch]

Add functions to get a profile's description, manufacturer, model and
copyright, and use them instead of implementing the same 10 times.

Also add a GimpColorProfile typedef which avoids both having to
include lcms globally or using a gpointer instead (which looks bad and
non-descriptive in an API).
parent a894f2a6
......@@ -38,6 +38,10 @@ EXPORTS
gimp_hsva_set
gimp_hwb_to_rgb
gimp_lcms_create_srgb_profile
gimp_lcms_profile_get_copyright
gimp_lcms_profile_get_description
gimp_lcms_profile_get_manufacturer
gimp_lcms_profile_get_model
gimp_param_rgb_get_type
gimp_param_spec_rgb
gimp_param_spec_rgb_has_alpha
......
......@@ -26,8 +26,11 @@
#include <lcms2.h>
#include <gio/gio.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "gimpcolortypes.h"
#include "gimplcms.h"
......@@ -42,6 +45,106 @@
**/
gchar *
gimp_lcms_profile_get_description (GimpColorProfile profile)
{
cmsUInt32Number size;
gchar *desc = NULL;
g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", NULL, 0);
if (size > 0)
{
gchar *data = g_new (gchar, size + 1);
size = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", data, size);
if (size > 0)
desc = gimp_any_to_utf8 (data, -1, NULL);
g_free (data);
}
return desc;
}
gchar *
gimp_lcms_profile_get_manufacturer (GimpColorProfile profile)
{
cmsUInt32Number size;
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 *
gimp_lcms_profile_get_model (GimpColorProfile profile)
{
cmsUInt32Number size;
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 *
gimp_lcms_profile_get_copyright (GimpColorProfile profile)
{
cmsUInt32Number size;
gchar *info = NULL;
g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoCopyright,
"en", "US", NULL, 0);
if (size > 0)
{
gchar *data = g_new (gchar, size + 1);
size = cmsGetProfileInfoASCII (profile, cmsInfoCopyright,
"en", "US", data, size);
if (size > 0)
info = gimp_any_to_utf8 (data, -1, NULL);
g_free (data);
}
return info;
}
/**
* gimp_lcms_create_srgb_profile:
*
......@@ -73,7 +176,7 @@
*
* Since: GIMP 2.10
**/
gpointer
GimpColorProfile
gimp_lcms_create_srgb_profile (void)
{
cmsHPROFILE srgb_profile;
......
......@@ -32,7 +32,15 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gpointer gimp_lcms_create_srgb_profile (void);
typedef gpointer GimpColorProfile;
gchar * gimp_lcms_profile_get_description (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_manufacturer (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_model (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_copyright (GimpColorProfile profile);
GimpColorProfile gimp_lcms_create_srgb_profile (void);
G_END_DECLS
......
......@@ -366,7 +366,6 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
GimpColorConfig *config = module->config;
cmsUInt32Number flags = 0;
cmsUInt32Number descSize = 0;
cmsHPROFILE rgb_profile;
cmsHPROFILE cmyk_profile;
gchar *descData = NULL;
......@@ -395,50 +394,9 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
! (cmyk_profile = cmsOpenProfileFromFile (config->cmyk_profile, "r")))
goto out;
descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoDescription,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoDescription,
"en", "US", descData, descSize);
if (descSize > 0)
{
name = descData;
}
else
{
g_free (descData);
descData = NULL;
}
}
if (name && ! g_utf8_validate (name, -1, NULL))
name = _("(invalid UTF-8 string)");
name = gimp_lcms_profile_get_description (cmyk_profile);
if (! name)
{
descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoModel,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (cmyk_profile, cmsInfoModel,
"en", "US", descData, descSize);
if (descSize > 0)
{
name = descData;
}
else
{
g_free (descData);
descData = NULL;
}
}
if (name && ! g_utf8_validate (name, -1, NULL))
name = _("(invalid UTF-8 string)");
}
name = gimp_lcms_profile_get_model (cmyk_profile);
text = g_strdup_printf (_("Profile: %s"), name);
gtk_label_set_text (GTK_LABEL (module->name_label), text);
......
......@@ -172,43 +172,9 @@ cdisplay_lcms_profile_get_info (cmsHPROFILE profile,
{
if (profile)
{
cmsUInt32Number descSize;
gchar *descData;
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", descData, descSize);
if (descSize > 0)
*name = descData;
else
g_free (descData);
}
*name = gimp_lcms_profile_get_description (profile);
if (! *name)
{
descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII(profile, cmsInfoModel,
"en", "US", descData, descSize);
if (descSize > 0)
*name = descData;
else
g_free (descData);
}
}
if (*name && ! g_utf8_validate (*name, -1, NULL))
{
g_free (*name);
*name = g_strdup (_("(invalid UTF-8 string)"));
}
*name = gimp_lcms_profile_get_model (profile);
if (! *name)
{
......@@ -216,24 +182,7 @@ cdisplay_lcms_profile_get_info (cmsHPROFILE profile,
*name = g_strdup (_("(unnamed profile)"));
}
descSize = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
"en", "US", descData, descSize);
if (descSize > 0)
*info = descData;
else
g_free (descData);
}
if (*info && ! g_utf8_validate (*info, -1, NULL))
{
g_free (*info);
*info = NULL;
}
*info = gimp_lcms_profile_get_manufacturer (profile);
}
else
{
......
......@@ -271,37 +271,9 @@ cdisplay_proof_combo_box_set_active (GimpColorProfileComboBox *combo,
if (profile)
{
cmsUInt32Number descSize;
gchar *descData;
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", descData, descSize);
if (descSize > 0)
label = gimp_any_to_utf8 (descData, -1, NULL);
g_free (descData);
}
label = gimp_lcms_profile_get_description (profile);
if (! label)
{
descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", descData, descSize);
if (descSize > 0)
label = gimp_any_to_utf8 (descData, -1, NULL);
g_free (descData);
}
}
label = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile);
}
......
......@@ -493,75 +493,6 @@ run (const gchar *name,
values[0].data.d_status = status;
}
static gchar *
lcms_icc_profile_get_name (cmsHPROFILE profile)
{
cmsUInt32Number descSize;
gchar *descData;
gchar *name = NULL;
descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", descData, descSize);
if (descSize > 0)
name = gimp_any_to_utf8 (descData, -1, NULL);
g_free (descData);
}
return name;
}
static gchar *
lcms_icc_profile_get_desc (cmsHPROFILE profile)
{
cmsUInt32Number descSize;
gchar *descData;
gchar *desc = NULL;
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoDescription,
"en", "US", descData, descSize);
if (descSize > 0)
desc = gimp_any_to_utf8 (descData, -1, NULL);
g_free (descData);
}
return desc;
}
static gchar *
lcms_icc_profile_get_info (cmsHPROFILE profile)
{
cmsUInt32Number descSize;
gchar *descData;
gchar *info = NULL;
descSize = cmsGetProfileInfoASCII (profile, cmsInfoCopyright,
"en", "US", NULL, 0);
if (descSize > 0)
{
descData = g_new (gchar, descSize + 1);
descSize = cmsGetProfileInfoASCII (profile, cmsInfoCopyright,
"en", "US", descData, descSize);
if (descSize > 0)
info = gimp_any_to_utf8 (descData, -1, NULL);
g_free (descData);
}
return info;
}
static gboolean
lcms_icc_profile_is_rgb (cmsHPROFILE profile)
{
......@@ -656,8 +587,8 @@ lcms_icc_apply (GimpColorConfig *config,
if (memcmp (src_md5, dest_md5, 16) == 0)
{
gchar *src_desc = lcms_icc_profile_get_desc (src_profile);
gchar *dest_desc = lcms_icc_profile_get_desc (dest_profile);
gchar *src_desc = gimp_lcms_profile_get_description (src_profile);
gchar *dest_desc = gimp_lcms_profile_get_description (dest_profile);
cmsCloseProfile (src_profile);
cmsCloseProfile (dest_profile);
......@@ -717,9 +648,9 @@ lcms_icc_info (GimpColorConfig *config,
if (profile)
{
if (name) *name = lcms_icc_profile_get_name (profile);
if (desc) *desc = lcms_icc_profile_get_desc (profile);
if (info) *info = lcms_icc_profile_get_info (profile);
if (name) *name = gimp_lcms_profile_get_model (profile);
if (desc) *desc = gimp_lcms_profile_get_description (profile);
if (info) *info = gimp_lcms_profile_get_copyright (profile);
cmsCloseProfile (profile);
}
......@@ -749,9 +680,9 @@ lcms_icc_file_info (const gchar *filename,
if (! profile)
return GIMP_PDB_EXECUTION_ERROR;
*name = lcms_icc_profile_get_name (profile);
*desc = lcms_icc_profile_get_desc (profile);
*info = lcms_icc_profile_get_info (profile);
*name = gimp_lcms_profile_get_model (profile);
*desc = gimp_lcms_profile_get_description (profile);
*info = gimp_lcms_profile_get_copyright (profile);
cmsCloseProfile (profile);
......@@ -929,8 +860,8 @@ lcms_image_apply_profile (gint32 image,
}
{
gchar *src = lcms_icc_profile_get_desc (src_profile);
gchar *dest = lcms_icc_profile_get_desc (dest_profile);
gchar *src = gimp_lcms_profile_get_description (src_profile);
gchar *dest = gimp_lcms_profile_get_description (dest_profile);
/* ICC color profile conversion */
gimp_progress_init_printf (_("Converting from '%s' to '%s'"), src, dest);
......@@ -1271,7 +1202,7 @@ lcms_icc_profile_src_label_new (gint32 image,
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
desc = lcms_icc_profile_get_desc (profile);
desc = gimp_lcms_profile_get_description (profile);
label = g_object_new (GTK_TYPE_LABEL,
"label", desc,
"wrap", TRUE,
......@@ -1298,7 +1229,7 @@ lcms_icc_profile_dest_label_new (cmsHPROFILE profile)
gchar *desc;
gchar *text;
desc = lcms_icc_profile_get_desc (profile);
desc = gimp_lcms_profile_get_description (profile);
text = g_strdup_printf (_("Convert the image to the RGB working space (%s)?"),
desc);
g_free (desc);
......@@ -1398,9 +1329,9 @@ lcms_icc_combo_box_set_active (GimpColorProfileComboBox *combo,
if (profile)
{
label = lcms_icc_profile_get_desc (profile);
label = gimp_lcms_profile_get_description (profile);
if (! label)
label = lcms_icc_profile_get_name (profile);
label = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile);
}
......@@ -1505,9 +1436,9 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
if (! profile)
profile = gimp_lcms_create_srgb_profile ();
name = lcms_icc_profile_get_desc (profile);
name = gimp_lcms_profile_get_description (profile);
if (! name)
name = lcms_icc_profile_get_name (profile);
name = gimp_lcms_profile_get_model (profile);
cmsCloseProfile (profile);
......@@ -1592,9 +1523,9 @@ lcms_dialog (GimpColorConfig *config,
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
name = lcms_icc_profile_get_desc (src_profile);
name = gimp_lcms_profile_get_description (src_profile);
if (! name)
name = lcms_icc_profile_get_name (src_profile);
name = gimp_lcms_profile_get_model (src_profile);
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment