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

@ -473,6 +473,8 @@ gimp_fill_options_get_format (GimpFillOptions *options,
return gimp_layer_mode_get_format (gimp_context_get_paint_mode (context), return gimp_layer_mode_get_format (gimp_context_get_paint_mode (context),
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
gimp_layer_mode_get_paint_composite_mode (
gimp_context_get_paint_mode (context)),
gimp_drawable_get_format (drawable)); gimp_drawable_get_format (drawable));
} }

View File

@ -57,8 +57,9 @@ gimp_gegl_create_flatten_node (const GimpRGB *background,
"value", c, "value", c,
"format", gimp_layer_mode_get_format ( "format", gimp_layer_mode_get_format (
GIMP_LAYER_MODE_NORMAL, GIMP_LAYER_MODE_NORMAL,
composite_space,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
composite_space,
GIMP_LAYER_COMPOSITE_AUTO,
NULL), NULL),
NULL); NULL);
g_object_unref (c); g_object_unref (c);

View File

@ -1423,10 +1423,11 @@ gimp_layer_mode_get_for_group (GimpLayerMode old_mode,
} }
const Babl * const Babl *
gimp_layer_mode_get_format (GimpLayerMode mode, gimp_layer_mode_get_format (GimpLayerMode mode,
GimpLayerColorSpace composite_space, GimpLayerColorSpace blend_space,
GimpLayerColorSpace blend_space, GimpLayerColorSpace composite_space,
const Babl *preferred_format) GimpLayerCompositeMode composite_mode,
const Babl *preferred_format)
{ {
/* for now, all modes perform i/o in the composite space. */ /* for now, all modes perform i/o in the composite space. */
(void) mode; (void) mode;
@ -1435,6 +1436,28 @@ gimp_layer_mode_get_format (GimpLayerMode mode,
if (composite_space == GIMP_LAYER_COLOR_SPACE_AUTO) if (composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
composite_space = gimp_layer_mode_get_composite_space (mode); 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) switch (composite_space)
{ {
case GIMP_LAYER_COLOR_SPACE_AUTO: case GIMP_LAYER_COLOR_SPACE_AUTO:

View File

@ -61,8 +61,9 @@ gboolean gimp_layer_mode_get_for_group (GimpLayer
GimpLayerMode *new_mode); GimpLayerMode *new_mode);
const Babl * gimp_layer_mode_get_format (GimpLayerMode mode, const Babl * gimp_layer_mode_get_format (GimpLayerMode mode,
GimpLayerColorSpace composite_space,
GimpLayerColorSpace blend_space, GimpLayerColorSpace blend_space,
GimpLayerColorSpace composite_space,
GimpLayerCompositeMode composite_mode,
const Babl *preferred_format); const Babl *preferred_format);
GimpLayerCompositeRegion gimp_layer_mode_get_included_region (GimpLayerMode mode, 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, format = gimp_layer_mode_get_format (self->layer_mode,
self->composite_space,
self->blend_space, self->blend_space,
self->composite_space,
self->composite_mode,
preferred_format); preferred_format);
gegl_operation_set_format (operation, "input", format); gegl_operation_set_format (operation, "input", format);

View File

@ -816,12 +816,16 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore *paint_core,
/* configure the canvas buffer */ /* configure the canvas buffer */
if ((x2 - x1) && (y2 - y1)) if ((x2 - x1) && (y2 - y1))
{ {
GimpTempBuf *temp_buf; GimpTempBuf *temp_buf;
const Babl *format; const Babl *format;
GimpLayerCompositeMode composite_mode;
composite_mode = gimp_layer_mode_get_paint_composite_mode (paint_mode);
format = gimp_layer_mode_get_format (paint_mode, format = gimp_layer_mode_get_format (paint_mode,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
composite_mode,
gimp_drawable_get_format (drawable)); gimp_drawable_get_format (drawable));
if (paint_core->paint_buffer && if (paint_core->paint_buffer &&

View File

@ -258,12 +258,16 @@ gimp_ink_get_paint_buffer (GimpPaintCore *paint_core,
/* configure the canvas buffer */ /* configure the canvas buffer */
if ((x2 - x1) && (y2 - y1)) if ((x2 - x1) && (y2 - y1))
{ {
GimpTempBuf *temp_buf; GimpTempBuf *temp_buf;
const Babl *format; const Babl *format;
GimpLayerCompositeMode composite_mode;
composite_mode = gimp_layer_mode_get_paint_composite_mode (paint_mode);
format = gimp_layer_mode_get_format (paint_mode, format = gimp_layer_mode_get_format (paint_mode,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO,
composite_mode,
gimp_drawable_get_format (drawable)); gimp_drawable_get_format (drawable));
temp_buf = gimp_temp_buf_new ((x2 - x1), (y2 - y1), temp_buf = gimp_temp_buf_new ((x2 - x1), (y2 - y1),

View File

@ -1886,8 +1886,9 @@ struct DoLayerBlend : Base
layer_mode.real_composite_mode = layer_mode.composite_mode; layer_mode.real_composite_mode = layer_mode.composite_mode;
iterator_format = gimp_layer_mode_get_format (params->paint_mode, iterator_format = gimp_layer_mode_get_format (params->paint_mode,
layer_mode.composite_space,
layer_mode.blend_space, layer_mode.blend_space,
layer_mode.composite_space,
layer_mode.composite_mode,
gimp_temp_buf_get_format (params->paint_buf)); gimp_temp_buf_get_format (params->paint_buf));
g_return_if_fail (gimp_temp_buf_get_format (params->paint_buf) == iterator_format); g_return_if_fail (gimp_temp_buf_get_format (params->paint_buf) == iterator_format);