libgimpconfig: add a preferred gray profile to GimpColorConfig

This commit is contained in:
Michael Natterer 2015-12-14 01:54:00 +01:00
parent 169f436e75
commit 5cbe6f2003
3 changed files with 101 additions and 2 deletions

View File

@ -65,6 +65,10 @@
_("The preferred RGB working space color profile. It will be offered " \
"next to the built-in RGB profile when a color profile can be chosen.")
#define GRAY_PROFILE_BLURB \
_("The preferred grayscale working space color profile. It will be offered " \
"next to the built-in grayscale profile when a color profile can be chosen.")
#define CMYK_PROFILE_BLURB \
_("The CMYK color profile used to convert between RGB and CMYK.")
@ -106,6 +110,7 @@ enum
PROP_0,
PROP_MODE,
PROP_RGB_PROFILE,
PROP_GRAY_PROFILE,
PROP_CMYK_PROFILE,
PROP_DISPLAY_PROFILE,
PROP_DISPLAY_PROFILE_FROM_GDK,
@ -133,6 +138,9 @@ static void gimp_color_config_get_property (GObject *object,
static void gimp_color_config_set_rgb_profile (GimpColorConfig *config,
const gchar *filename,
GError **error);
static void gimp_color_config_set_gray_profile (GimpColorConfig *config,
const gchar *filename,
GError **error);
static void gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
const gchar *filename,
GError **error);
@ -173,6 +181,10 @@ gimp_color_config_class_init (GimpColorConfigClass *klass)
"rgb-profile", RGB_PROFILE_BLURB,
GIMP_CONFIG_PATH_FILE, NULL,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRAY_PROFILE,
"gray-profile", GRAY_PROFILE_BLURB,
GIMP_CONFIG_PATH_FILE, NULL,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_CMYK_PROFILE,
"cmyk-profile", CMYK_PROFILE_BLURB,
GIMP_CONFIG_PATH_FILE, NULL,
@ -241,6 +253,9 @@ gimp_color_config_finalize (GObject *object)
if (color_config->rgb_profile)
g_free (color_config->rgb_profile);
if (color_config->gray_profile)
g_free (color_config->gray_profile);
if (color_config->cmyk_profile)
g_free (color_config->cmyk_profile);
@ -275,6 +290,11 @@ gimp_color_config_set_property (GObject *object,
g_value_get_string (value),
&error);
break;
case PROP_GRAY_PROFILE:
gimp_color_config_set_gray_profile (color_config,
g_value_get_string (value),
&error);
break;
case PROP_CMYK_PROFILE:
gimp_color_config_set_cmyk_profile (color_config,
g_value_get_string (value),
@ -344,6 +364,9 @@ gimp_color_config_get_property (GObject *object,
case PROP_RGB_PROFILE:
g_value_set_string (value, color_config->rgb_profile);
break;
case PROP_GRAY_PROFILE:
g_value_set_string (value, color_config->gray_profile);
break;
case PROP_CMYK_PROFILE:
g_value_set_string (value, color_config->cmyk_profile);
break;
@ -415,6 +438,37 @@ gimp_color_config_get_rgb_color_profile (GimpColorConfig *config,
return profile;
}
GimpColorProfile *
gimp_color_config_get_gray_color_profile (GimpColorConfig *config,
GError **error)
{
GimpColorProfile *profile = NULL;
g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (config->gray_profile)
{
GFile *file = g_file_new_for_path (config->gray_profile);
profile = gimp_color_profile_new_from_file (file, error);
if (profile && ! gimp_color_profile_is_gray (profile))
{
g_object_unref (profile);
profile = NULL;
g_set_error (error, GIMP_CONFIG_ERROR, 0,
_("Color profile '%s' is not for GRAY color space."),
gimp_file_get_utf8_name (file));
}
g_object_unref (file);
}
return profile;
}
GimpColorProfile *
gimp_color_config_get_cmyk_color_profile (GimpColorConfig *config,
GError **error)
@ -530,6 +584,47 @@ gimp_color_config_set_rgb_profile (GimpColorConfig *config,
}
}
static void
gimp_color_config_set_gray_profile (GimpColorConfig *config,
const gchar *filename,
GError **error)
{
gboolean success = TRUE;
if (filename)
{
GimpColorProfile *profile;
GFile *file = g_file_new_for_path (filename);
profile = gimp_color_profile_new_from_file (file, error);
if (profile)
{
if (! gimp_color_profile_is_gray (profile))
{
g_set_error (error, GIMP_CONFIG_ERROR, 0,
_("Color profile '%s' is not for GRAY color space."),
gimp_file_get_utf8_name (file));
success = FALSE;
}
g_object_unref (profile);
}
else
{
success = FALSE;
}
g_object_unref (file);
}
if (success)
{
g_free (config->gray_profile);
config->gray_profile = g_strdup (filename);
}
}
static void
gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
const gchar *filename,

View File

@ -58,12 +58,13 @@ struct _GimpColorConfig
gboolean display_use_black_point_compensation;
gboolean simulation_use_black_point_compensation;
gchar *gray_profile;
/*< private >*/
/* Padding for future expansion */
#if (GLIB_SIZEOF_VOID_P == 8)
void (* _gimp_reserved2) (void);
#endif
void (* _gimp_reserved3) (void);
#endif
void (* _gimp_reserved4) (void);
void (* _gimp_reserved5) (void);
void (* _gimp_reserved6) (void);
@ -81,6 +82,8 @@ GType gimp_color_config_get_type (void) G_GNUC_CON
GimpColorProfile * gimp_color_config_get_rgb_color_profile (GimpColorConfig *config,
GError **error);
GimpColorProfile * gimp_color_config_get_gray_color_profile (GimpColorConfig *config,
GError **error);
GimpColorProfile * gimp_color_config_get_cmyk_color_profile (GimpColorConfig *config,
GError **error);
GimpColorProfile * gimp_color_config_get_display_color_profile (GimpColorConfig *config,

View File

@ -1,6 +1,7 @@
EXPORTS
gimp_color_config_get_cmyk_color_profile
gimp_color_config_get_display_color_profile
gimp_color_config_get_gray_color_profile
gimp_color_config_get_printer_color_profile
gimp_color_config_get_rgb_color_profile
gimp_color_config_get_type