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 <lcms2.h>
#include <gegl.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);
cmsCloseProfile (profile);
gimp_lcms_profile_close (profile);
}

View File

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

View File

@ -23,8 +23,6 @@
#include <string.h>
#include <lcms2.h>
#include <gegl.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,
profile);
cmsCloseProfile (profile);
gimp_lcms_profile_close (profile);
}
g_object_unref (file);

View File

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

View File

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

View File

@ -347,36 +347,14 @@ colorsel_cmyk_adj_update (GtkAdjustment *adj,
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
colorsel_cmyk_config_changed (ColorselCmyk *module)
{
GimpColorSelector *selector = GIMP_COLOR_SELECTOR (module);
GimpColorConfig *config = module->config;
cmsUInt32Number flags = 0;
cmsHPROFILE rgb_profile = NULL;
cmsHPROFILE cmyk_profile = NULL;
GimpColorProfile rgb_profile = NULL;
GimpColorProfile cmyk_profile = NULL;
gchar *label;
gchar *summary;
gchar *text;
@ -399,8 +377,11 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
if (! config)
goto out;
rgb_profile = color_config_get_rgb_profile (config);
cmyk_profile = color_config_get_cmyk_profile (config);
rgb_profile = gimp_color_config_get_rgb_profile (config, NULL);
cmyk_profile = gimp_color_config_get_cmyk_profile (config, NULL);
if (! rgb_profile)
rgb_profile = gimp_lcms_create_srgb_profile ();
if (! cmyk_profile)
goto out;
@ -434,10 +415,10 @@ colorsel_cmyk_config_changed (ColorselCmyk *module)
out:
if (rgb_profile)
cmsCloseProfile (rgb_profile);
gimp_lcms_profile_close (rgb_profile);
if (cmyk_profile)
cmsCloseProfile (cmyk_profile);
gimp_lcms_profile_close (cmyk_profile);
if (! module->in_destruction)
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_display_profile (CdisplayLcms *lcms);
static cmsHPROFILE cdisplay_lcms_get_printer_profile (CdisplayLcms *lcms);
static void cdisplay_lcms_attach_labelled (GtkTable *table,
gint row,
@ -295,7 +294,7 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
return;
case GIMP_COLOR_MANAGEMENT_SOFTPROOF:
proof_profile = cdisplay_lcms_get_printer_profile (lcms);
proof_profile = gimp_color_config_get_printer_profile (config, NULL);
/* fallthru */
case GIMP_COLOR_MANAGEMENT_DISPLAY:
@ -342,7 +341,7 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
config->simulation_intent,
config->display_intent,
softproof_flags);
cmsCloseProfile (proof_profile);
gimp_lcms_profile_close (proof_profile);
}
else if (src_profile || dest_profile)
{
@ -366,10 +365,10 @@ cdisplay_lcms_changed (GimpColorDisplay *display)
}
if (dest_profile)
cmsCloseProfile (dest_profile);
gimp_lcms_profile_close (dest_profile);
if (src_profile)
cmsCloseProfile (src_profile);
gimp_lcms_profile_close (src_profile);
}
static cmsHPROFILE
@ -379,6 +378,7 @@ cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
GimpColorManaged *managed;
cmsHPROFILE profile = NULL;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
managed = gimp_color_display_get_managed (GIMP_COLOR_DISPLAY (lcms));
if (managed)
@ -391,24 +391,13 @@ cdisplay_lcms_get_rgb_profile (CdisplayLcms *lcms)
if (profile && ! gimp_lcms_profile_is_rgb (profile))
{
cmsCloseProfile (profile);
gimp_lcms_profile_close (profile);
profile = NULL;
}
}
if (! profile)
{
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;
}
}
profile = gimp_color_config_get_rgb_profile (config, NULL);
return profile;
}
@ -542,25 +531,12 @@ cdisplay_lcms_get_display_profile (CdisplayLcms *lcms)
}
#endif
if (! profile && config->display_profile)
profile = cmsOpenProfileFromFile (config->display_profile, "r");
if (! profile)
profile = gimp_color_config_get_display_profile (config, NULL);
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
cdisplay_lcms_attach_labelled (GtkTable *table,
gint row,
@ -593,10 +569,13 @@ static void
cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
const gchar *name)
{
GtkWidget *label;
cmsHPROFILE profile = NULL;
gchar *text = NULL;
gchar *tooltip = NULL;
GimpColorConfig *config;
GtkWidget *label;
cmsHPROFILE profile = NULL;
gchar *text = NULL;
gchar *tooltip = NULL;
config = gimp_color_display_get_config (GIMP_COLOR_DISPLAY (lcms));
label = g_object_get_data (G_OBJECT (lcms), name);
@ -613,7 +592,7 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
}
else if (strcmp (name, "printer-profile") == 0)
{
profile = cdisplay_lcms_get_printer_profile (lcms);
profile = gimp_color_config_get_printer_profile (config, NULL);
}
else
{
@ -629,7 +608,7 @@ cdisplay_lcms_update_profile_label (CdisplayLcms *lcms,
g_free (tooltip);
if (profile)
cmsCloseProfile (profile);
gimp_lcms_profile_close (profile);
}
static void

View File

@ -322,9 +322,10 @@ cdisplay_proof_configure (GimpColorDisplay *display)
static void
cdisplay_proof_changed (GimpColorDisplay *display)
{
CdisplayProof *proof = CDISPLAY_PROOF (display);
cmsHPROFILE rgb_profile;
cmsHPROFILE proof_profile;
CdisplayProof *proof = CDISPLAY_PROOF (display);
GimpColorProfile rgb_profile;
GimpColorProfile proof_profile;
GFile *file;
if (proof->transform)
{
@ -337,7 +338,9 @@ cdisplay_proof_changed (GimpColorDisplay *display)
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)
{

View File

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

View File

@ -595,38 +595,29 @@ static gpointer
jpeg_load_cmyk_transform (guint8 *profile_data,
gsize profile_len)
{
GimpColorConfig *config = gimp_get_color_configuration ();
cmsHPROFILE cmyk_profile = NULL;
cmsHPROFILE rgb_profile = NULL;
cmsUInt32Number flags = 0;
cmsHTRANSFORM transform;
GimpColorConfig *config = gimp_get_color_configuration ();
GimpColorProfile cmyk_profile = NULL;
GimpColorProfile rgb_profile = NULL;
cmsUInt32Number flags = 0;
cmsHTRANSFORM transform;
/* try to load the embedded CMYK profile */
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))
{
cmsCloseProfile (cmyk_profile);
cmyk_profile = NULL;
}
gimp_lcms_profile_close (cmyk_profile);
cmyk_profile = NULL;
}
}
/* if that fails, try to load the CMYK profile configured in the prefs */
if (! cmyk_profile && config->cmyk_profile)
{
cmyk_profile = cmsOpenProfileFromFile (config->cmyk_profile, "r");
if (cmyk_profile && ! gimp_lcms_profile_is_cmyk (cmyk_profile))
{
cmsCloseProfile (cmyk_profile);
cmyk_profile = NULL;
}
}
if (! cmyk_profile)
cmyk_profile = gimp_color_config_get_cmyk_profile (config, NULL);
/* bail out if we can't load any 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 */
if (config->rgb_profile)
{
rgb_profile = cmsOpenProfileFromFile (config->rgb_profile, "r");
if (rgb_profile && ! gimp_lcms_profile_is_rgb (rgb_profile))
{
cmsCloseProfile (rgb_profile);
rgb_profile = NULL;
}
}
rgb_profile = gimp_color_config_get_rgb_profile (config, NULL);
/* make the real sRGB profile as a fallback */
if (! rgb_profile)
{
rgb_profile = gimp_lcms_create_srgb_profile ();
}
rgb_profile = gimp_lcms_create_srgb_profile ();
if (config->display_intent ==
GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC)
@ -664,8 +644,8 @@ jpeg_load_cmyk_transform (guint8 *profile_data,
config->display_intent,
flags);
cmsCloseProfile (cmyk_profile);
cmsCloseProfile (rgb_profile);
gimp_lcms_profile_close (cmyk_profile);
gimp_lcms_profile_close (rgb_profile);
g_object_unref (config);