app: clean up most "non-linear" vs. "perceptual" confusion

There should never be an image using GIMP_TRC_PERCEPTUAL, but things
should work if one is encountered anyway.

In the Image -> Precision menu and the Convert Precision dialog, have
menu items / radio buttons for both non-linear and perceptual, but
hide the perceptual choice unless the image is in perceptual TRC mode.

This should eliminate the possibility to create perceptual TRC images
from the GUI.
This commit is contained in:
Michael Natterer 2019-05-31 16:48:19 +02:00
parent 3cad4aa4c2
commit eec1df23a5
3 changed files with 59 additions and 32 deletions

View File

@ -246,17 +246,23 @@ static const GimpRadioActionEntry image_convert_precision_actions[] =
static const GimpRadioActionEntry image_convert_trc_actions[] =
{
{ "image-convert-gamma", NULL,
NC_("image-convert-action", "Perceptual gamma (sRGB)"), NULL,
NC_("image-convert-action",
"Convert the image to perceptual (sRGB) gamma"),
GIMP_TRC_NON_LINEAR, GIMP_HELP_IMAGE_CONVERT_GAMMA },
{ "image-convert-linear", NULL,
NC_("image-convert-action", "Linear light"), NULL,
NC_("image-convert-action",
"Convert the image to linear light"),
GIMP_TRC_LINEAR, GIMP_HELP_IMAGE_CONVERT_GAMMA }
GIMP_TRC_LINEAR, GIMP_HELP_IMAGE_CONVERT_GAMMA },
{ "image-convert-non-linear", NULL,
NC_("image-convert-action", "Non-Linear"), NULL,
NC_("image-convert-action",
"Convert the image to non-linear gamma from the color profile"),
GIMP_TRC_NON_LINEAR, GIMP_HELP_IMAGE_CONVERT_GAMMA },
{ "image-convert-perceptual", NULL,
NC_("image-convert-action", "Perceptual (sRGB)"), NULL,
NC_("image-convert-action",
"Convert the image to perceptual (sRGB) gamma"),
GIMP_TRC_PERCEPTUAL, GIMP_HELP_IMAGE_CONVERT_GAMMA }
};
static const GimpEnumActionEntry image_flip_actions[] =
@ -361,6 +367,15 @@ image_actions_update (GimpActionGroup *group,
gboolean profile_hidden = FALSE;
gboolean profile = FALSE;
#define SET_LABEL(action,label) \
gimp_action_group_set_action_label (group, action, (label))
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
#define SET_ACTIVE(action,condition) \
gimp_action_group_set_action_active (group, action, (condition) != 0)
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
if (image)
{
GimpContainer *layers;
@ -368,10 +383,13 @@ image_actions_update (GimpActionGroup *group,
GimpImageBaseType base_type;
GimpPrecision precision;
GimpComponentType component_type;
GimpTRCType trc;
base_type = gimp_image_get_base_type (image);
precision = gimp_image_get_precision (image);
component_type = gimp_image_get_component_type (image);
trc = gimp_babl_format_get_trc
(gimp_image_get_layer_format (image, FALSE));
switch (base_type)
{
@ -380,7 +398,7 @@ image_actions_update (GimpActionGroup *group,
case GIMP_INDEXED: action = "image-convert-indexed"; break;
}
gimp_action_group_set_action_active (group, action, TRUE);
SET_ACTIVE (action, TRUE);
switch (component_type)
{
@ -392,21 +410,28 @@ image_actions_update (GimpActionGroup *group,
case GIMP_COMPONENT_TYPE_DOUBLE: action = "image-convert-double"; break;
}
gimp_action_group_set_action_active (group, action, TRUE);
SET_ACTIVE (action, TRUE);
if (gimp_babl_format_get_trc (gimp_image_get_layer_format (image,
FALSE)) ==
GIMP_TRC_LINEAR)
switch (trc)
{
gimp_action_group_set_action_active (group, "image-convert-linear",
TRUE);
}
else
{
gimp_action_group_set_action_active (group, "image-convert-gamma",
TRUE);
case GIMP_TRC_LINEAR:
action = "image-convert-linear";
SET_VISIBLE ("image-convert-perceptual", FALSE);
break;
case GIMP_TRC_NON_LINEAR:
action = "image-convert-non-linear";
SET_VISIBLE ("image-convert-perceptual", FALSE);
break;
case GIMP_TRC_PERCEPTUAL:
action = "image-convert-perceptual";
SET_VISIBLE ("image-convert-perceptual", TRUE);
break;
}
SET_ACTIVE (action, TRUE);
is_indexed = (base_type == GIMP_INDEXED);
is_u8_gamma = (precision == GIMP_PRECISION_U8_NON_LINEAR);
is_double = (component_type == GIMP_COMPONENT_TYPE_DOUBLE);
@ -421,15 +446,10 @@ image_actions_update (GimpActionGroup *group,
profile_srgb = gimp_image_get_use_srgb_profile (image, &profile_hidden);
profile = (gimp_image_get_color_profile (image) != NULL);
}
#define SET_LABEL(action,label) \
gimp_action_group_set_action_label (group, action, (label))
#define SET_SENSITIVE(action,condition) \
gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
#define SET_ACTIVE(action,condition) \
gimp_action_group_set_action_active (group, action, (condition) != 0)
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
else
{
SET_VISIBLE ("image-convert-perceptual", FALSE);
}
SET_SENSITIVE ("image-duplicate", image);
@ -460,8 +480,9 @@ image_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("image-convert-double", image && !is_indexed);
SET_VISIBLE ("image-convert-double", is_double);
SET_SENSITIVE ("image-convert-gamma", image);
SET_SENSITIVE ("image-convert-linear", image && !is_indexed);
SET_SENSITIVE ("image-convert-linear", image && !is_indexed);
SET_SENSITIVE ("image-convert-non-linear", image);
SET_SENSITIVE ("image-convert-perceptual", image && !is_indexed);
SET_SENSITIVE ("image-color-profile-use-srgb", image && (profile || profile_hidden));
SET_ACTIVE ("image-color-profile-use-srgb", image && profile_srgb);

View File

@ -81,6 +81,7 @@ convert_precision_dialog_new (GimpImage *image,
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *perceptual_radio;
const gchar *enum_desc;
gchar *blurb;
const Babl *old_format;
@ -209,9 +210,13 @@ convert_precision_dialog_new (GimpImage *image,
GIMP_TRC_NON_LINEAR, NULL,
_("Perceptual (sRGB)"),
GIMP_TRC_PERCEPTUAL, NULL,
GIMP_TRC_PERCEPTUAL, &perceptual_radio,
NULL);
if (private->trc != GIMP_TRC_PERCEPTUAL)
gtk_widget_hide (perceptual_radio);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);

View File

@ -377,8 +377,9 @@
<menuitem action="image-convert-float" />
<menuitem action="image-convert-double" />
<separator />
<menuitem action="image-convert-gamma" />
<menuitem action="image-convert-linear" />
<menuitem action="image-convert-non-linear" />
<menuitem action="image-convert-perceptual" />
<separator />
</menu>
<menu action="image-color-management-menu" name="Color Management">