Skip to content

Commit 5cbe6f2

Browse files
committed
libgimpconfig: add a preferred gray profile to GimpColorConfig
1 parent 169f436 commit 5cbe6f2

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

libgimpconfig/gimpcolorconfig.c

+95
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
_("The preferred RGB working space color profile. It will be offered " \
6666
"next to the built-in RGB profile when a color profile can be chosen.")
6767

68+
#define GRAY_PROFILE_BLURB \
69+
_("The preferred grayscale working space color profile. It will be offered " \
70+
"next to the built-in grayscale profile when a color profile can be chosen.")
71+
6872
#define CMYK_PROFILE_BLURB \
6973
_("The CMYK color profile used to convert between RGB and CMYK.")
7074

@@ -106,6 +110,7 @@ enum
106110
PROP_0,
107111
PROP_MODE,
108112
PROP_RGB_PROFILE,
113+
PROP_GRAY_PROFILE,
109114
PROP_CMYK_PROFILE,
110115
PROP_DISPLAY_PROFILE,
111116
PROP_DISPLAY_PROFILE_FROM_GDK,
@@ -133,6 +138,9 @@ static void gimp_color_config_get_property (GObject *object,
133138
static void gimp_color_config_set_rgb_profile (GimpColorConfig *config,
134139
const gchar *filename,
135140
GError **error);
141+
static void gimp_color_config_set_gray_profile (GimpColorConfig *config,
142+
const gchar *filename,
143+
GError **error);
136144
static void gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
137145
const gchar *filename,
138146
GError **error);
@@ -173,6 +181,10 @@ gimp_color_config_class_init (GimpColorConfigClass *klass)
173181
"rgb-profile", RGB_PROFILE_BLURB,
174182
GIMP_CONFIG_PATH_FILE, NULL,
175183
GIMP_PARAM_STATIC_STRINGS);
184+
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_GRAY_PROFILE,
185+
"gray-profile", GRAY_PROFILE_BLURB,
186+
GIMP_CONFIG_PATH_FILE, NULL,
187+
GIMP_PARAM_STATIC_STRINGS);
176188
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_CMYK_PROFILE,
177189
"cmyk-profile", CMYK_PROFILE_BLURB,
178190
GIMP_CONFIG_PATH_FILE, NULL,
@@ -241,6 +253,9 @@ gimp_color_config_finalize (GObject *object)
241253
if (color_config->rgb_profile)
242254
g_free (color_config->rgb_profile);
243255

256+
if (color_config->gray_profile)
257+
g_free (color_config->gray_profile);
258+
244259
if (color_config->cmyk_profile)
245260
g_free (color_config->cmyk_profile);
246261

@@ -275,6 +290,11 @@ gimp_color_config_set_property (GObject *object,
275290
g_value_get_string (value),
276291
&error);
277292
break;
293+
case PROP_GRAY_PROFILE:
294+
gimp_color_config_set_gray_profile (color_config,
295+
g_value_get_string (value),
296+
&error);
297+
break;
278298
case PROP_CMYK_PROFILE:
279299
gimp_color_config_set_cmyk_profile (color_config,
280300
g_value_get_string (value),
@@ -344,6 +364,9 @@ gimp_color_config_get_property (GObject *object,
344364
case PROP_RGB_PROFILE:
345365
g_value_set_string (value, color_config->rgb_profile);
346366
break;
367+
case PROP_GRAY_PROFILE:
368+
g_value_set_string (value, color_config->gray_profile);
369+
break;
347370
case PROP_CMYK_PROFILE:
348371
g_value_set_string (value, color_config->cmyk_profile);
349372
break;
@@ -415,6 +438,37 @@ gimp_color_config_get_rgb_color_profile (GimpColorConfig *config,
415438
return profile;
416439
}
417440

441+
GimpColorProfile *
442+
gimp_color_config_get_gray_color_profile (GimpColorConfig *config,
443+
GError **error)
444+
{
445+
GimpColorProfile *profile = NULL;
446+
447+
g_return_val_if_fail (GIMP_IS_COLOR_CONFIG (config), NULL);
448+
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
449+
450+
if (config->gray_profile)
451+
{
452+
GFile *file = g_file_new_for_path (config->gray_profile);
453+
454+
profile = gimp_color_profile_new_from_file (file, error);
455+
456+
if (profile && ! gimp_color_profile_is_gray (profile))
457+
{
458+
g_object_unref (profile);
459+
profile = NULL;
460+
461+
g_set_error (error, GIMP_CONFIG_ERROR, 0,
462+
_("Color profile '%s' is not for GRAY color space."),
463+
gimp_file_get_utf8_name (file));
464+
}
465+
466+
g_object_unref (file);
467+
}
468+
469+
return profile;
470+
}
471+
418472
GimpColorProfile *
419473
gimp_color_config_get_cmyk_color_profile (GimpColorConfig *config,
420474
GError **error)
@@ -530,6 +584,47 @@ gimp_color_config_set_rgb_profile (GimpColorConfig *config,
530584
}
531585
}
532586

587+
static void
588+
gimp_color_config_set_gray_profile (GimpColorConfig *config,
589+
const gchar *filename,
590+
GError **error)
591+
{
592+
gboolean success = TRUE;
593+
594+
if (filename)
595+
{
596+
GimpColorProfile *profile;
597+
GFile *file = g_file_new_for_path (filename);
598+
599+
profile = gimp_color_profile_new_from_file (file, error);
600+
601+
if (profile)
602+
{
603+
if (! gimp_color_profile_is_gray (profile))
604+
{
605+
g_set_error (error, GIMP_CONFIG_ERROR, 0,
606+
_("Color profile '%s' is not for GRAY color space."),
607+
gimp_file_get_utf8_name (file));
608+
success = FALSE;
609+
}
610+
611+
g_object_unref (profile);
612+
}
613+
else
614+
{
615+
success = FALSE;
616+
}
617+
618+
g_object_unref (file);
619+
}
620+
621+
if (success)
622+
{
623+
g_free (config->gray_profile);
624+
config->gray_profile = g_strdup (filename);
625+
}
626+
}
627+
533628
static void
534629
gimp_color_config_set_cmyk_profile (GimpColorConfig *config,
535630
const gchar *filename,

libgimpconfig/gimpcolorconfig.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ struct _GimpColorConfig
5858
gboolean display_use_black_point_compensation;
5959
gboolean simulation_use_black_point_compensation;
6060

61+
gchar *gray_profile;
62+
6163
/*< private >*/
6264
/* Padding for future expansion */
6365
#if (GLIB_SIZEOF_VOID_P == 8)
64-
void (* _gimp_reserved2) (void);
65-
#endif
6666
void (* _gimp_reserved3) (void);
67+
#endif
6768
void (* _gimp_reserved4) (void);
6869
void (* _gimp_reserved5) (void);
6970
void (* _gimp_reserved6) (void);
@@ -81,6 +82,8 @@ GType gimp_color_config_get_type (void) G_GNUC_CON
8182

8283
GimpColorProfile * gimp_color_config_get_rgb_color_profile (GimpColorConfig *config,
8384
GError **error);
85+
GimpColorProfile * gimp_color_config_get_gray_color_profile (GimpColorConfig *config,
86+
GError **error);
8487
GimpColorProfile * gimp_color_config_get_cmyk_color_profile (GimpColorConfig *config,
8588
GError **error);
8689
GimpColorProfile * gimp_color_config_get_display_color_profile (GimpColorConfig *config,

libgimpconfig/gimpconfig.def

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
EXPORTS
22
gimp_color_config_get_cmyk_color_profile
33
gimp_color_config_get_display_color_profile
4+
gimp_color_config_get_gray_color_profile
45
gimp_color_config_get_printer_color_profile
56
gimp_color_config_get_rgb_color_profile
67
gimp_color_config_get_type

0 commit comments

Comments
 (0)