mirror of https://github.com/GNOME/gimp.git
Bug 756389 - Color-managing grayscale images
Allow to set profiles on grayscale images. Change profile validation to check for image type and profile type. Actually the patch simply makes some pieces of code less restrictive. Change user-visible strings in the profile dialogs accordingly. Change PDB docs accordingly.
This commit is contained in:
parent
50309bea12
commit
5098338470
|
@ -55,18 +55,18 @@
|
|||
|
||||
/* local function prototypes */
|
||||
|
||||
static void gimp_image_convert_profile_rgb (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress);
|
||||
static void gimp_image_convert_profile_indexed (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress);
|
||||
static void gimp_image_convert_profile_layers (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress);
|
||||
static void gimp_image_convert_profile_colormap (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -246,18 +246,23 @@ gimp_image_validate_color_profile (GimpImage *image,
|
|||
|
||||
if (gimp_image_get_base_type (image) == GIMP_GRAY)
|
||||
{
|
||||
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("ICC profile validation failed: "
|
||||
"Cannot attach a color profile to a GRAY image"));
|
||||
return FALSE;
|
||||
if (! gimp_color_profile_is_gray (profile))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("ICC profile validation failed: "
|
||||
"Color profile is not for GRAY color space"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (! gimp_color_profile_is_rgb (profile))
|
||||
else
|
||||
{
|
||||
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("ICC profile validation failed: "
|
||||
"Color profile is not for RGB color space"));
|
||||
return FALSE;
|
||||
if (! gimp_color_profile_is_rgb (profile))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("ICC profile validation failed: "
|
||||
"Color profile is not for RGB color space"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_builtin)
|
||||
|
@ -302,41 +307,65 @@ gimp_image_set_color_profile (GimpImage *image,
|
|||
GimpColorProfile *
|
||||
gimp_image_get_builtin_color_profile (GimpImage *image)
|
||||
{
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *gray_profile = NULL;
|
||||
static GimpColorProfile *linear_gray_profile = NULL;
|
||||
const Babl *format;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_srgb ();
|
||||
linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
|
||||
}
|
||||
|
||||
format = gimp_image_get_layer_format (image, FALSE);
|
||||
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
if (gimp_image_get_base_type (image) == GIMP_GRAY)
|
||||
{
|
||||
if (! srgb_profile)
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_srgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (srgb_profile),
|
||||
(gpointer) &srgb_profile);
|
||||
}
|
||||
if (! linear_gray_profile)
|
||||
{
|
||||
linear_gray_profile = gimp_color_profile_new_linear_gray ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
|
||||
(gpointer) &linear_gray_profile);
|
||||
}
|
||||
|
||||
return linear_rgb_profile;
|
||||
return linear_gray_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! gray_profile)
|
||||
{
|
||||
gray_profile = gimp_color_profile_new_srgb_gray ();
|
||||
g_object_add_weak_pointer (G_OBJECT (gray_profile),
|
||||
(gpointer) &gray_profile);
|
||||
}
|
||||
|
||||
return gray_profile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! linear_rgb_profile)
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
|
||||
(gpointer) &linear_rgb_profile);
|
||||
}
|
||||
if (! linear_rgb_profile)
|
||||
{
|
||||
linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
|
||||
(gpointer) &linear_rgb_profile);
|
||||
}
|
||||
|
||||
return srgb_profile;
|
||||
return linear_rgb_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_srgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (srgb_profile),
|
||||
(gpointer) &srgb_profile);
|
||||
}
|
||||
|
||||
return srgb_profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,20 +404,18 @@ gimp_image_convert_color_profile (GimpImage *image,
|
|||
switch (gimp_image_get_base_type (image))
|
||||
{
|
||||
case GIMP_RGB:
|
||||
gimp_image_convert_profile_rgb (image,
|
||||
src_profile, dest_profile,
|
||||
intent, bpc,
|
||||
progress);
|
||||
break;
|
||||
|
||||
case GIMP_GRAY:
|
||||
gimp_image_convert_profile_layers (image,
|
||||
src_profile, dest_profile,
|
||||
intent, bpc,
|
||||
progress);
|
||||
break;
|
||||
|
||||
case GIMP_INDEXED:
|
||||
gimp_image_convert_profile_indexed (image,
|
||||
src_profile, dest_profile,
|
||||
intent, bpc,
|
||||
progress);
|
||||
gimp_image_convert_profile_colormap (image,
|
||||
src_profile, dest_profile,
|
||||
intent, bpc,
|
||||
progress);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -418,9 +445,6 @@ gimp_image_import_color_profile (GimpImage *image,
|
|||
|
||||
config = image->gimp->config->color_management;
|
||||
|
||||
if (gimp_image_get_base_type (image) == GIMP_GRAY)
|
||||
return;
|
||||
|
||||
if (config->mode == GIMP_COLOR_MANAGEMENT_OFF)
|
||||
return;
|
||||
|
||||
|
@ -480,12 +504,12 @@ gimp_image_import_color_profile (GimpImage *image,
|
|||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_image_convert_profile_rgb (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress)
|
||||
gimp_image_convert_profile_layers (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress)
|
||||
{
|
||||
GList *layers;
|
||||
GList *list;
|
||||
|
@ -543,12 +567,12 @@ gimp_image_convert_profile_rgb (GimpImage *image,
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_image_convert_profile_indexed (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress)
|
||||
gimp_image_convert_profile_colormap (GimpImage *image,
|
||||
GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile,
|
||||
GimpColorRenderingIntent intent,
|
||||
gboolean bpc,
|
||||
GimpProgress *progress)
|
||||
{
|
||||
cmsHPROFILE src_lcms;
|
||||
cmsHPROFILE dest_lcms;
|
||||
|
|
|
@ -1387,7 +1387,7 @@ gimp_image_color_managed_get_color_profile (GimpColorManaged *managed)
|
|||
|
||||
profile = gimp_image_get_color_profile (image);
|
||||
|
||||
if (! profile && gimp_image_get_base_type (image) != GIMP_GRAY)
|
||||
if (! profile)
|
||||
profile = gimp_image_get_builtin_color_profile (image);
|
||||
|
||||
return profile;
|
||||
|
|
|
@ -309,28 +309,44 @@ color_profile_combo_box_new (ProfileDialog *dialog)
|
|||
|
||||
profile = gimp_image_get_builtin_color_profile (dialog->image);
|
||||
|
||||
label = g_strdup_printf (_("Built-in RGB (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
if (gimp_image_get_base_type (dialog->image) == GIMP_GRAY)
|
||||
{
|
||||
label = g_strdup_printf (_("Built-in GRAY (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
|
||||
profile = gimp_color_config_get_gray_color_profile (dialog->config, &error);
|
||||
}
|
||||
else
|
||||
{
|
||||
label = g_strdup_printf (_("Built-in RGB (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
|
||||
profile = gimp_color_config_get_rgb_color_profile (dialog->config, &error);
|
||||
}
|
||||
|
||||
gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
|
||||
NULL, label);
|
||||
|
||||
g_free (label);
|
||||
|
||||
profile = gimp_color_config_get_rgb_color_profile (dialog->config, &error);
|
||||
|
||||
if (profile)
|
||||
{
|
||||
GFile *file = g_file_new_for_path (dialog->config->rgb_profile);
|
||||
|
||||
label = g_strdup_printf (_("Preferred RGB (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
if (gimp_image_get_base_type (dialog->image) == GIMP_GRAY)
|
||||
{
|
||||
label = g_strdup_printf (_("Preferred GRAY (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
}
|
||||
else
|
||||
{
|
||||
label = g_strdup_printf (_("Preferred RGB (%s)"),
|
||||
gimp_color_profile_get_label (profile));
|
||||
}
|
||||
|
||||
g_object_unref (profile);
|
||||
|
||||
gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
|
||||
file, label);
|
||||
|
||||
g_object_unref (file);
|
||||
g_free (label);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ color_profile_import_dialog_run (GimpImage *image,
|
|||
GtkWidget *toggle;
|
||||
GimpColorProfile *src_profile;
|
||||
GimpColorProfilePolicy policy;
|
||||
const gchar *title;
|
||||
const gchar *frame_title;
|
||||
gchar *text;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_COLOR_PROFILE_POLICY_KEEP);
|
||||
|
@ -73,9 +75,20 @@ color_profile_import_dialog_run (GimpImage *image,
|
|||
src_profile = gimp_image_get_color_profile (image);
|
||||
*dest_profile = gimp_image_get_builtin_color_profile (image);
|
||||
|
||||
if (gimp_image_get_base_type (image) == GIMP_GRAY)
|
||||
{
|
||||
title = _("Convert to Grayscale Working Space?");
|
||||
frame_title = _("Convert the image to the grayscale working space?");
|
||||
}
|
||||
else
|
||||
{
|
||||
title = _("Convert to RGB Working Space?");
|
||||
frame_title = _("Convert the image to the RGB working space?");
|
||||
}
|
||||
|
||||
dialog =
|
||||
gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
|
||||
_("Convert to RGB Working Space?"),
|
||||
title,
|
||||
"gimp-image-color-profile-import",
|
||||
NULL,
|
||||
_("Import the image from a color profile"),
|
||||
|
@ -112,7 +125,7 @@ color_profile_import_dialog_run (GimpImage *image,
|
|||
gtk_container_add (GTK_CONTAINER (frame), label);
|
||||
gtk_widget_show (label);
|
||||
|
||||
frame = gimp_frame_new (_("Convert the image to the RGB working space?"));
|
||||
frame = gimp_frame_new (frame_title);
|
||||
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
||||
gtk_widget_show (frame);
|
||||
|
||||
|
|
|
@ -667,23 +667,31 @@ static gboolean
|
|||
gimp_color_profile_can_gegl_copy (GimpColorProfile *src_profile,
|
||||
GimpColorProfile *dest_profile)
|
||||
{
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *gray_profile = NULL;
|
||||
static GimpColorProfile *linear_gray_profile = NULL;
|
||||
|
||||
if (gimp_color_profile_is_equal (src_profile, dest_profile))
|
||||
return TRUE;
|
||||
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_srgb ();
|
||||
linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
|
||||
srgb_profile = gimp_color_profile_new_srgb ();
|
||||
linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
|
||||
gray_profile = gimp_color_profile_new_srgb_gray ();
|
||||
linear_gray_profile = gimp_color_profile_new_linear_gray ();
|
||||
}
|
||||
|
||||
if ((gimp_color_profile_is_equal (src_profile, srgb_profile) ||
|
||||
gimp_color_profile_is_equal (src_profile, linear_rgb_profile))
|
||||
if ((gimp_color_profile_is_equal (src_profile, srgb_profile) ||
|
||||
gimp_color_profile_is_equal (src_profile, linear_rgb_profile) ||
|
||||
gimp_color_profile_is_equal (src_profile, gray_profile) ||
|
||||
gimp_color_profile_is_equal (src_profile, linear_gray_profile))
|
||||
&&
|
||||
(gimp_color_profile_is_equal (dest_profile, srgb_profile) ||
|
||||
gimp_color_profile_is_equal (dest_profile, linear_rgb_profile)))
|
||||
(gimp_color_profile_is_equal (dest_profile, srgb_profile) ||
|
||||
gimp_color_profile_is_equal (dest_profile, linear_rgb_profile) ||
|
||||
gimp_color_profile_is_equal (dest_profile, gray_profile) ||
|
||||
gimp_color_profile_is_equal (dest_profile, linear_gray_profile)))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -712,9 +720,7 @@ gimp_gegl_convert_color_profile (GeglBuffer *src_buffer,
|
|||
src_format = gegl_buffer_get_format (src_buffer);
|
||||
dest_format = gegl_buffer_get_format (dest_buffer);
|
||||
|
||||
if ((gimp_babl_format_get_base_type (src_format) != GIMP_RGB) ||
|
||||
(gimp_babl_format_get_base_type (dest_format) != GIMP_RGB) ||
|
||||
gimp_color_profile_can_gegl_copy (src_profile, dest_profile))
|
||||
if (gimp_color_profile_can_gegl_copy (src_profile, dest_profile))
|
||||
{
|
||||
gegl_buffer_copy (src_buffer, src_rect, GEGL_ABYSS_NONE,
|
||||
dest_buffer, dest_rect);
|
||||
|
|
|
@ -112,8 +112,8 @@ image_get_effective_color_profile_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (profile)
|
||||
{
|
||||
const guint8 *data;
|
||||
gsize length;
|
||||
const guint8 *data;
|
||||
gsize length;
|
||||
|
||||
data = gimp_color_profile_get_icc_profile (profile, &length);
|
||||
|
||||
|
@ -368,7 +368,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
|
|||
gimp_procedure_set_static_strings (procedure,
|
||||
"gimp-image-get-effective-color-profile",
|
||||
"Returns the color profile that is used for the image",
|
||||
"This procedure returns the color profile that is actually used for this image, which is the profile returned by 'gimp-image-get-color-profile' if the image has a profile assigned, or a generated default RGB profile. If the image is not RGB or INDEXED, NULL is returned.",
|
||||
"This procedure returns the color profile that is actually used for this image, which is the profile returned by 'gimp-image-get-color-profile' if the image has a profile assigned, or a generated default RGB or GRAY profile, according to the image's type.",
|
||||
"Michael Natterer <mitch@gimp.org>",
|
||||
"Michael Natterer",
|
||||
"2015",
|
||||
|
@ -466,7 +466,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
|
|||
gimp_procedure_set_static_strings (procedure,
|
||||
"gimp-image-convert-color-profile",
|
||||
"Convert the image's layers to a color profile",
|
||||
"This procedure converts from the image's color profile (or the default RGB profile if none is set) to the given color profile. Only RGB color profiles are accepted.",
|
||||
"This procedure converts from the image's color profile (or the default RGB or GRAY profile if none is set) to the given color profile. Only RGB and GRAY color profiles are accepted, according to the image's type.",
|
||||
"Michael Natterer <mitch@gimp.org>",
|
||||
"Michael Natterer",
|
||||
"2015",
|
||||
|
@ -513,7 +513,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
|
|||
gimp_procedure_set_static_strings (procedure,
|
||||
"gimp-image-convert-color-profile-from-file",
|
||||
"Convert the image's layers to a color profile",
|
||||
"This procedure converts from the image's color profile (or the default RGB profile if none is set) to an ICC profile precified by 'uri'. Only RGB color profiles are accepted.",
|
||||
"This procedure converts from the image's color profile (or the default RGB or GRAY profile if none is set) to an ICC profile precified by 'uri'. Only RGB and GRAY color profiles are accepted, according to the image's type.",
|
||||
"Michael Natterer <mitch@gimp.org>",
|
||||
"Michael Natterer",
|
||||
"2015",
|
||||
|
|
|
@ -90,8 +90,8 @@ _gimp_image_get_color_profile (gint32 image_ID,
|
|||
* This procedure returns the color profile that is actually used for
|
||||
* this image, which is the profile returned by
|
||||
* gimp_image_get_color_profile() if the image has a profile assigned,
|
||||
* or a generated default RGB profile. If the image is not RGB or
|
||||
* INDEXED, NULL is returned.
|
||||
* or a generated default RGB or GRAY profile, according to the image's
|
||||
* type.
|
||||
*
|
||||
* Returns: The image's serialized color profile. The returned value
|
||||
* must be freed with g_free().
|
||||
|
@ -213,8 +213,9 @@ gimp_image_set_color_profile_from_file (gint32 image_ID,
|
|||
* Convert the image's layers to a color profile
|
||||
*
|
||||
* This procedure converts from the image's color profile (or the
|
||||
* default RGB profile if none is set) to the given color profile. Only
|
||||
* RGB color profiles are accepted.
|
||||
* default RGB or GRAY profile if none is set) to the given color
|
||||
* profile. Only RGB and GRAY color profiles are accepted, according to
|
||||
* the image's type.
|
||||
*
|
||||
* Returns: TRUE on success.
|
||||
*
|
||||
|
@ -257,8 +258,9 @@ _gimp_image_convert_color_profile (gint32 image_ID,
|
|||
* Convert the image's layers to a color profile
|
||||
*
|
||||
* This procedure converts from the image's color profile (or the
|
||||
* default RGB profile if none is set) to an ICC profile precified by
|
||||
* 'uri'. Only RGB color profiles are accepted.
|
||||
* default RGB or GRAY profile if none is set) to an ICC profile
|
||||
* precified by 'uri'. Only RGB and GRAY color profiles are accepted,
|
||||
* according to the image's type.
|
||||
*
|
||||
* Returns: TRUE on success.
|
||||
*
|
||||
|
|
|
@ -67,8 +67,7 @@ sub image_get_effective_color_profile {
|
|||
This procedure returns the color profile that is actually used for
|
||||
this image, which is the profile returned by
|
||||
gimp_image_get_color_profile() if the image has a profile assigned, or
|
||||
a generated default RGB profile. If the image is not RGB or INDEXED,
|
||||
NULL is returned.
|
||||
a generated default RGB or GRAY profile, according to the image's type.
|
||||
HELP
|
||||
|
||||
&mitch_pdb_misc('2015', '2.10');
|
||||
|
@ -94,8 +93,8 @@ HELP
|
|||
|
||||
if (profile)
|
||||
{
|
||||
const guint8 *data;
|
||||
gsize length;
|
||||
const guint8 *data;
|
||||
gsize length;
|
||||
|
||||
data = gimp_color_profile_get_icc_profile (profile, &length);
|
||||
|
||||
|
@ -206,8 +205,9 @@ sub image_convert_color_profile {
|
|||
|
||||
$help = <<'HELP';
|
||||
This procedure converts from the image's color profile (or the default
|
||||
RGB profile if none is set) to the given color profile. Only RGB color
|
||||
profiles are accepted.
|
||||
RGB or GRAY profile if none is set) to the given color profile. Only
|
||||
RGB and GRAY color profiles are accepted, according to the image's
|
||||
type.
|
||||
HELP
|
||||
|
||||
&mitch_pdb_misc('2015', '2.10');
|
||||
|
@ -258,8 +258,9 @@ sub image_convert_color_profile_from_file {
|
|||
|
||||
$help = <<'HELP';
|
||||
This procedure converts from the image's color profile (or the default
|
||||
RGB profile if none is set) to an ICC profile precified by 'uri'.
|
||||
Only RGB color profiles are accepted.
|
||||
RGB or GRAY profile if none is set) to an ICC profile precified by
|
||||
'uri'. Only RGB and GRAY color profiles are accepted, according to
|
||||
the image's type.
|
||||
HELP
|
||||
|
||||
&mitch_pdb_misc('2015', '2.10');
|
||||
|
|
Loading…
Reference in New Issue