app: disregard composite space in non-union alpha-only layer modes

In gimp_layer_mode_get_format(), disregard the requested composite
space when selecting the format, if the input layer mode is alpha-
only, and the requested composite mode is not UNION, since, in this
case, the layer mode doesn't combine the layer/backdrop colors, and
rather only modifies the alpha of one of them.  This allows us to
use the preferred format, avoiding gamma conversion.

This particularly improves the performance of the Eraser tool in
perceptual images.

(cherry picked from commit a5962e4049)
This commit is contained in:
Ell
2019-05-24 01:33:53 -04:00
parent 9501d63b20
commit 7313686192
8 changed files with 49 additions and 12 deletions

View File

@ -1423,10 +1423,11 @@ gimp_layer_mode_get_for_group (GimpLayerMode old_mode,
}
const Babl *
gimp_layer_mode_get_format (GimpLayerMode mode,
GimpLayerColorSpace composite_space,
GimpLayerColorSpace blend_space,
const Babl *preferred_format)
gimp_layer_mode_get_format (GimpLayerMode mode,
GimpLayerColorSpace blend_space,
GimpLayerColorSpace composite_space,
GimpLayerCompositeMode composite_mode,
const Babl *preferred_format)
{
/* for now, all modes perform i/o in the composite space. */
(void) mode;
@ -1435,6 +1436,28 @@ gimp_layer_mode_get_format (GimpLayerMode mode,
if (composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
composite_space = gimp_layer_mode_get_composite_space (mode);
if (composite_mode == GIMP_LAYER_COMPOSITE_AUTO)
composite_mode = gimp_layer_mode_get_composite_mode (mode);
if (gimp_layer_mode_is_alpha_only (mode))
{
switch (composite_mode)
{
case GIMP_LAYER_COMPOSITE_AUTO:
case GIMP_LAYER_COMPOSITE_UNION:
break;
case GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP:
case GIMP_LAYER_COMPOSITE_CLIP_TO_LAYER:
case GIMP_LAYER_COMPOSITE_INTERSECTION:
/* alpha-only layer modes don't combine colors in non-union composite
* modes, hence we can disregard the composite space.
*/
composite_space = GIMP_LAYER_COLOR_SPACE_AUTO;
break;
}
}
switch (composite_space)
{
case GIMP_LAYER_COLOR_SPACE_AUTO:

View File

@ -61,8 +61,9 @@ gboolean gimp_layer_mode_get_for_group (GimpLayer
GimpLayerMode *new_mode);
const Babl * gimp_layer_mode_get_format (GimpLayerMode mode,
GimpLayerColorSpace composite_space,
GimpLayerColorSpace blend_space,
GimpLayerColorSpace composite_space,
GimpLayerCompositeMode composite_mode,
const Babl *preferred_format);
GimpLayerCompositeRegion gimp_layer_mode_get_included_region (GimpLayerMode mode,

View File

@ -359,8 +359,9 @@ gimp_operation_layer_mode_prepare (GeglOperation *operation)
}
format = gimp_layer_mode_get_format (self->layer_mode,
self->composite_space,
self->blend_space,
self->composite_space,
self->composite_mode,
preferred_format);
gegl_operation_set_format (operation, "input", format);