Use the newly added profile utility functions all over the place

This commit is contained in:
Michael Natterer 2015-05-06 16:38:57 +02:00
parent 54553487f2
commit 6c800db1cc
10 changed files with 71 additions and 161 deletions

View file

@ -22,8 +22,6 @@
#include <string.h> #include <string.h>
#include <lcms2.h>
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -122,5 +120,5 @@ gimp_image_profile_view_update (GimpImageParasiteView *view)
gimp_color_profile_view_set_profile (profile_view->profile_view, profile); gimp_color_profile_view_set_profile (profile_view->profile_view, profile);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
} }

View file

@ -52,7 +52,6 @@ AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"LibGimpWidgets\" \ -DG_LOG_DOMAIN=\"LibGimpWidgets\" \
-DGIMP_WIDGETS_COMPILATION \ -DGIMP_WIDGETS_COMPILATION \
-I$(top_srcdir) \ -I$(top_srcdir) \
$(LCMS_CFLAGS) \
$(GEGL_CFLAGS) \ $(GEGL_CFLAGS) \
$(GTK_CFLAGS) \ $(GTK_CFLAGS) \
-I$(includedir) -I$(includedir)
@ -268,7 +267,6 @@ libgimpwidgets_@GIMP_API_VERSION@_la_LIBADD = \
$(libgimpbase) \ $(libgimpbase) \
$(libgimpcolor) \ $(libgimpcolor) \
$(libgimpconfig) \ $(libgimpconfig) \
$(LCMS_LIBS) \
$(GEGL_LIBS) \ $(GEGL_LIBS) \
$(GTK_LIBS) \ $(GTK_LIBS) \
$(libm) $(libm)

View file

@ -23,8 +23,6 @@
#include <string.h> #include <string.h>
#include <lcms2.h>
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -209,7 +207,7 @@ gimp_color_profile_chooser_dialog_update_preview (GimpColorProfileChooserDialog
{ {
gimp_color_profile_view_set_profile (dialog->priv->profile_view, gimp_color_profile_view_set_profile (dialog->priv->profile_view,
profile); profile);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
} }
g_object_unref (file); g_object_unref (file);

View file

@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <lcms2.h>
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -426,7 +424,7 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
if (filename && ! (label && *label)) if (filename && ! (label && *label))
{ {
GFile *file; GFile *file;
cmsHPROFILE profile; GimpColorProfile profile;
GError *error = NULL; GError *error = NULL;
file = g_file_new_for_path (filename); file = g_file_new_for_path (filename);
@ -441,7 +439,7 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
else else
{ {
l = gimp_lcms_profile_get_label (profile); l = gimp_lcms_profile_get_label (profile);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
} }
} }
else else

View file

@ -22,8 +22,6 @@
#include <string.h> #include <string.h>
#include <lcms2.h>
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>

View file

@ -347,36 +347,14 @@ colorsel_cmyk_adj_update (GtkAdjustment *adj,
gimp_color_selector_color_changed (selector); gimp_color_selector_color_changed (selector);
} }
static cmsHPROFILE
color_config_get_rgb_profile (GimpColorConfig *config)
{
cmsHPROFILE profile = NULL;
if (config->rgb_profile)
profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
return profile ? profile : gimp_lcms_create_srgb_profile ();
}
static cmsHPROFILE
color_config_get_cmyk_profile (GimpColorConfig *config)
{
cmsHPROFILE profile = NULL;
if (config->cmyk_profile)
profile = cmsOpenProfileFromFile (config->cmyk_profile, "r");
return profile;
}
static void static void
colorsel_cmyk_config_changed (ColorselCmyk *module) colorsel_cmyk_config_changed (ColorselCmyk *module)
{ {
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module); GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
GimpColorConfig *config = module->config; GimpColorConfig *config = module->config;
cmsUInt32Number flags = 0; cmsUInt32Number flags = 0;
cmsHPROFILE rgb_profile = NULL; GimpColorProfile rgb_profile = NULL;
cmsHPROFILE cmyk_profile = NULL; GimpColorProfile cmyk_profile = NULL;
gchar *label; gchar *label;
gchar *summary; gchar *summary;
gchar *text; gchar *text;
@ -399,8 +377,11 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
if (! config) if (! config)
goto out; goto out;
rgb_profile = color_config_get_rgb_profile (config); rgb_profile = gimp_color_config_get_rgb_profile (config, NULL);
cmyk_profile = color_config_get_cmyk_profile (config); cmyk_profile = gimp_color_config_get_cmyk_profile (config, NULL);
if (! rgb_profile)
rgb_profile = gimp_lcms_create_srgb_profile ();
if (! cmyk_profile) if (! cmyk_profile)
goto out; goto out;
@ -434,10 +415,10 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
out: out:
if (rgb_profile) if (rgb_profile)
cmsCloseProfile (rgb_profile); gimp_lcms_profile_close (rgb_profile);
if (cmyk_profile) if (cmyk_profile)
cmsCloseProfile (cmyk_profile); gimp_lcms_profile_close (cmyk_profile);
if (! module->in_destruction) if (! module->in_destruction)
colorsel_cmyk_set_color (selector, &selector->rgb, &selector->hsv); colorsel_cmyk_set_color (selector, &selector->rgb, &selector->hsv);

View file

@ -83,7 +83,6 @@ static void cdisplay_lcms_changed (GimpColorDisplay *displ
static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms); static cmsHPROFILE cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms);
static cmsHPROFILE cdisplay_lcms_get_display_profile (CdisplayLcms *lcms); static cmsHPROFILE cdisplay_lcms_get_display_profile (CdisplayLcms *lcms);
static cmsHPROFILE cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms);
static void cdisplay_lcms_attach_labelled (GtkTable *table, static void cdisplay_lcms_attach_labelled (GtkTable *table,
gint row, gint row,
@ -295,7 +294,7 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
return; return;
case GIMP_COLOR_MANAGEMENT_SOFTPROOF: case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
proof_profile = cdisplay_lcms_get_printer_profile (lcms); proof_profile = gimp_color_config_get_printer_profile (config, NULL);
/* fallthru */ /* fallthru */
case GIMP_COLOR_MANAGEMENT_DISPLAY: case GIMP_COLOR_MANAGEMENT_DISPLAY:
@ -342,7 +341,7 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
config->simulation_intent, config->simulation_intent,
config->display_intent, config->display_intent,
softproof_flags); softproof_flags);
cmsCloseProfile (proof_profile); gimp_lcms_profile_close (proof_profile);
} }
else if (src_profile || dest_profile) else if (src_profile || dest_profile)
{ {
@ -366,10 +365,10 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
} }
if (dest_profile) if (dest_profile)
cmsCloseProfile (dest_profile); gimp_lcms_profile_close (dest_profile);
if (src_profile) if (src_profile)
cmsCloseProfile (src_profile); gimp_lcms_profile_close (src_profile);
} }
static cmsHPROFILE static cmsHPROFILE
@ -379,6 +378,7 @@ cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
GimpColorManaged *managed; GimpColorManaged *managed;
cmsHPROFILE profile = NULL; cmsHPROFILE profile = NULL;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms)); managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
if (managed) if (managed)
@ -391,24 +391,13 @@ cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
if (profile && ! gimp_lcms_profile_is_rgb (profile)) if (profile && ! gimp_lcms_profile_is_rgb (profile))
{ {
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
profile = NULL; profile = NULL;
} }
} }
if (! profile) if (! profile)
{ profile = gimp_color_config_get_rgb_profile (config, NULL);
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
if (config->rgb_profile)
profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
if (profile && ! gimp_lcms_profile_is_rgb (profile))
{
cmsCloseProfile (profile);
profile = NULL;
}
}
return profile; return profile;
} }
@ -542,25 +531,12 @@ cdisplay_lcms_get_display_profile (CdisplayLcms *lcms)
} }
#endif #endif
if (! profile && config->display_profile) if (! profile)
profile = cmsOpenProfileFromFile (config->display_profile, "r"); profile = gimp_color_config_get_display_profile (config, NULL);
return profile; return profile;
} }
static cmsHPROFILE
cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms)
{
GimpColorConfig *config;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
if (config->printer_profile)
return cmsOpenProfileFromFile (config->printer_profile, "r");
return NULL;
}
static void static void
cdisplay_lcms_attach_labelled (GtkTable *table, cdisplay_lcms_attach_labelled (GtkTable *table,
gint row, gint row,
@ -593,11 +569,14 @@ static void
cdisplay_lcms_update_profile_label (CdisplayLcms *lcms, cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
const gchar *name) const gchar *name)
{ {
GimpColorConfig *config;
GtkWidget *label; GtkWidget *label;
cmsHPROFILE profile = NULL; cmsHPROFILE profile = NULL;
gchar *text = NULL; gchar *text = NULL;
gchar *tooltip = NULL; gchar *tooltip = NULL;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
label = g_object_get_data (G_OBJECT (lcms), name); label = g_object_get_data (G_OBJECT (lcms), name);
if (! label) if (! label)
@ -613,7 +592,7 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
} }
else if (strcmp (name, "printer-profile") == 0) else if (strcmp (name, "printer-profile") == 0)
{ {
profile = cdisplay_lcms_get_printer_profile (lcms); profile = gimp_color_config_get_printer_profile (config, NULL);
} }
else else
{ {
@ -629,7 +608,7 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
g_free (tooltip); g_free (tooltip);
if (profile) if (profile)
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
} }
static void static void

View file

@ -323,8 +323,9 @@ static void
cdisplay_proof_changed (GimpColorDisplay *display) cdisplay_proof_changed (GimpColorDisplay *display)
{ {
CdisplayProof *proof = CDISPLAY_PROOF (display); CdisplayProof *proof = CDISPLAY_PROOF (display);
cmsHPROFILE rgb_profile; GimpColorProfile rgb_profile;
cmsHPROFILE proof_profile; GimpColorProfile proof_profile;
GFile *file;
if (proof->transform) if (proof->transform)
{ {
@ -337,7 +338,9 @@ cdisplay_proof_changed (GimpColorDisplay *display)
rgb_profile = gimp_lcms_create_srgb_profile (); rgb_profile = gimp_lcms_create_srgb_profile ();
proof_profile = cmsOpenProfileFromFile (proof->profile, "r"); file = g_file_new_for_path (proof->profile);
proof_profile = gimp_lcms_profile_open_from_file (file, NULL);
g_object_unref (file);
if (proof_profile) if (proof_profile)
{ {

View file

@ -562,7 +562,7 @@ lcms_icc_apply (GimpColorConfig *config,
g_message (_("Color profile '%s' is not for RGB color space."), g_message (_("Color profile '%s' is not for RGB color space."),
gimp_file_get_utf8_name (file)); gimp_file_get_utf8_name (file));
cmsCloseProfile (dest_profile); gimp_lcms_profile_close (dest_profile);
g_object_unref (file); g_object_unref (file);
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
} }
@ -590,8 +590,8 @@ lcms_icc_apply (GimpColorConfig *config,
gchar *src_label = gimp_lcms_profile_get_label (src_profile); gchar *src_label = gimp_lcms_profile_get_label (src_profile);
gchar *dest_label = gimp_lcms_profile_get_label (dest_profile); gchar *dest_label = gimp_lcms_profile_get_label (dest_profile);
cmsCloseProfile (src_profile); gimp_lcms_profile_close (src_profile);
cmsCloseProfile (dest_profile); gimp_lcms_profile_close (dest_profile);
g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n"); g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n");
g_printerr (" %s\n", src_label); g_printerr (" %s\n", src_label);
@ -620,8 +620,8 @@ lcms_icc_apply (GimpColorConfig *config,
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
} }
cmsCloseProfile (src_profile); gimp_lcms_profile_close (src_profile);
cmsCloseProfile (dest_profile); gimp_lcms_profile_close (dest_profile);
if (file) if (file)
g_object_unref (file); g_object_unref (file);
@ -657,7 +657,7 @@ lcms_icc_info (GimpColorConfig *config,
if (desc) *desc = gimp_lcms_profile_get_description (profile); if (desc) *desc = gimp_lcms_profile_get_description (profile);
if (info) *info = gimp_lcms_profile_get_summary (profile); if (info) *info = gimp_lcms_profile_get_summary (profile);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
return GIMP_PDB_SUCCESS; return GIMP_PDB_SUCCESS;
} }
@ -680,7 +680,7 @@ lcms_icc_file_info (GFile *file,
*desc = gimp_lcms_profile_get_description (profile); *desc = gimp_lcms_profile_get_description (profile);
*info = gimp_lcms_profile_get_summary (profile); *info = gimp_lcms_profile_get_summary (profile);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
return GIMP_PDB_SUCCESS; return GIMP_PDB_SUCCESS;
} }
@ -709,20 +709,7 @@ lcms_image_get_profile (GimpColorConfig *config,
} }
else if (config->rgb_profile) else if (config->rgb_profile)
{ {
GFile *file = g_file_new_for_path (config->rgb_profile); profile = gimp_color_config_get_rgb_profile (config, error);
profile = gimp_lcms_profile_open_from_file (file, error);
if (profile && ! gimp_lcms_profile_is_rgb (profile))
{
g_set_error (error, 0, 0,
_("Color profile '%s' is not for RGB color space"),
gimp_file_get_utf8_name (file));
cmsCloseProfile (profile);
profile = NULL;
}
g_object_unref (file);
} }
return profile; return profile;
@ -757,7 +744,7 @@ lcms_image_set_profile (gint32 image,
profile_data = gimp_lcms_profile_save_to_data (file_profile, profile_data = gimp_lcms_profile_save_to_data (file_profile,
&profile_length, &profile_length,
&error); &error);
cmsCloseProfile (file_profile); gimp_lcms_profile_close (file_profile);
if (! profile_data) if (! profile_data)
{ {
@ -1270,29 +1257,19 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
if (config->rgb_profile) if (config->rgb_profile)
{ {
GFile *file = g_file_new_for_path (config->rgb_profile);
GError *error = NULL; GError *error = NULL;
profile = gimp_lcms_profile_open_from_file (file, &error); profile = gimp_color_config_get_rgb_profile (config, &error);
if (! profile) if (! profile)
{ {
g_message ("%s", error->message); g_message ("%s", error->message);
g_clear_error (&error); g_clear_error (&error);
} }
else if (! gimp_lcms_profile_is_rgb (profile))
{
g_message (_("Color profile '%s' is not for RGB color space."),
gimp_filename_to_utf8 (config->rgb_profile));
cmsCloseProfile (profile);
profile = NULL;
}
else else
{ {
rgb_filename = config->rgb_profile; rgb_filename = config->rgb_profile;
} }
g_object_unref (file);
} }
if (! profile) if (! profile)
@ -1302,7 +1279,7 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
label = g_strdup_printf (_("RGB workspace (%s)"), name); label = g_strdup_printf (_("RGB workspace (%s)"), name);
g_free (name); g_free (name);
cmsCloseProfile (profile); gimp_lcms_profile_close (profile);
gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
rgb_filename, label); rgb_filename, label);
@ -1480,10 +1457,10 @@ lcms_dialog (GimpColorConfig *config,
} }
else else
{ {
gimp_message (_("Destination profile is not for RGB color space.")); g_message (_("Destination profile is not for RGB color space."));
} }
cmsCloseProfile (dest_profile); gimp_lcms_profile_close (dest_profile);
} }
if (file) if (file)
@ -1497,7 +1474,7 @@ lcms_dialog (GimpColorConfig *config,
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
cmsCloseProfile (src_profile); gimp_lcms_profile_close (src_profile);
return (run ? return (run ?
(success ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR) : (success ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR) :

View file

@ -596,37 +596,28 @@ jpeg_load_cmyk_transform (guint8 *profile_data,
gsize profile_len) gsize profile_len)
{ {
GimpColorConfig *config = gimp_get_color_configuration (); GimpColorConfig *config = gimp_get_color_configuration ();
cmsHPROFILE cmyk_profile = NULL; GimpColorProfile cmyk_profile = NULL;
cmsHPROFILE rgb_profile = NULL; GimpColorProfile rgb_profile = NULL;
cmsUInt32Number flags = 0; cmsUInt32Number flags = 0;
cmsHTRANSFORM transform; cmsHTRANSFORM transform;
/* try to load the embedded CMYK profile */ /* try to load the embedded CMYK profile */
if (profile_data) if (profile_data)
{ {
cmyk_profile = cmsOpenProfileFromMem (profile_data, profile_len); cmyk_profile = gimp_lcms_profile_open_from_data (profile_data,
profile_len,
NULL);
if (cmyk_profile) if (cmyk_profile && ! gimp_lcms_profile_is_cmyk (cmyk_profile))
{ {
if (! gimp_lcms_profile_is_cmyk (cmyk_profile)) gimp_lcms_profile_close (cmyk_profile);
{
cmsCloseProfile (cmyk_profile);
cmyk_profile = NULL; cmyk_profile = NULL;
} }
} }
}
/* if that fails, try to load the CMYK profile configured in the prefs */ /* if that fails, try to load the CMYK profile configured in the prefs */
if (! cmyk_profile && config->cmyk_profile) if (! cmyk_profile)
{ cmyk_profile = gimp_color_config_get_cmyk_profile (config, NULL);
cmyk_profile = cmsOpenProfileFromFile (config->cmyk_profile, "r");
if (cmyk_profile && ! gimp_lcms_profile_is_cmyk (cmyk_profile))
{
cmsCloseProfile (cmyk_profile);
cmyk_profile = NULL;
}
}
/* bail out if we can't load any CMYK profile */ /* bail out if we can't load any CMYK profile */
if (! cmyk_profile) if (! cmyk_profile)
@ -636,22 +627,11 @@ jpeg_load_cmyk_transform (guint8 *profile_data,
} }
/* try to load the RGB profile configured in the prefs */ /* try to load the RGB profile configured in the prefs */
if (config->rgb_profile) rgb_profile = gimp_color_config_get_rgb_profile (config, NULL);
{
rgb_profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
if (rgb_profile && ! gimp_lcms_profile_is_rgb (rgb_profile))
{
cmsCloseProfile (rgb_profile);
rgb_profile = NULL;
}
}
/* make the real sRGB profile as a fallback */ /* make the real sRGB profile as a fallback */
if (! rgb_profile) if (! rgb_profile)
{
rgb_profile = gimp_lcms_create_srgb_profile (); rgb_profile = gimp_lcms_create_srgb_profile ();
}
if (config->display_intent == if (config->display_intent ==
GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC) GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
@ -664,8 +644,8 @@ jpeg_load_cmyk_transform (guint8 *profile_data,
config->display_intent, config->display_intent,
flags); flags);
cmsCloseProfile (cmyk_profile); gimp_lcms_profile_close (cmyk_profile);
cmsCloseProfile (rgb_profile); gimp_lcms_profile_close (rgb_profile);
g_object_unref (config); g_object_unref (config);