From 65f85e7078906c9a06d62b741cbbd91c175bf3d1 Mon Sep 17 00:00:00 2001 From: Elle Stone Date: Sun, 9 Jun 2019 17:01:49 -0400 Subject: [PATCH] Make luma_lighten/darken_only blend modes work in AnyRGB --- .../gimpoperationlayermode-blend.c | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/app/operations/layer-modes/gimpoperationlayermode-blend.c b/app/operations/layer-modes/gimpoperationlayermode-blend.c index 8087f98bf9..f88a87a8ef 100644 --- a/app/operations/layer-modes/gimpoperationlayermode-blend.c +++ b/app/operations/layer-modes/gimpoperationlayermode-blend.c @@ -815,6 +815,11 @@ gimp_operation_layer_mode_blend_luma_darken_only (GeglOperation *operation, gfloat *comp, gint samples) { + const Babl *space = gegl_operation_get_source_space (operation, "input"); + double red_luminance, green_luminance, blue_luminance; + babl_space_get_rgb_luminance (space, + &red_luminance, &green_luminance, &blue_luminance); + while (samples--) { if (in[ALPHA] != 0.0f && layer[ALPHA] != 0.0f) @@ -823,8 +828,13 @@ gimp_operation_layer_mode_blend_luma_darken_only (GeglOperation *operation, gfloat src_luminance; gint c; - dest_luminance = GIMP_RGB_LUMINANCE (in[0], in[1], in[2]); - src_luminance = GIMP_RGB_LUMINANCE (layer[0], layer[1], layer[2]); + dest_luminance = (in[0] * red_luminance) + + (in[1] * green_luminance) + + (in[2] * blue_luminance); + + src_luminance = (layer[0] * red_luminance) + + (layer[1] * green_luminance) + + (layer[2] * blue_luminance); if (dest_luminance <= src_luminance) { @@ -853,6 +863,11 @@ gimp_operation_layer_mode_blend_luma_lighten_only (GeglOperation *operation, gfloat *comp, gint samples) { + const Babl *space = gegl_operation_get_source_space (operation, "input"); + double red_luminance, green_luminance, blue_luminance; + babl_space_get_rgb_luminance (space, + &red_luminance, &green_luminance, &blue_luminance); + while (samples--) { if (in[ALPHA] != 0.0f && layer[ALPHA] != 0.0f) @@ -861,8 +876,13 @@ gimp_operation_layer_mode_blend_luma_lighten_only (GeglOperation *operation, gfloat src_luminance; gint c; - dest_luminance = GIMP_RGB_LUMINANCE (in[0], in[1], in[2]); - src_luminance = GIMP_RGB_LUMINANCE (layer[0], layer[1], layer[2]); + dest_luminance = (in[0] * red_luminance) + + (in[1] * green_luminance) + + (in[2] * blue_luminance); + + src_luminance = (layer[0] * red_luminance) + + (layer[1] * green_luminance) + + (layer[2] * blue_luminance); if (dest_luminance >= src_luminance) { @@ -891,14 +911,15 @@ gimp_operation_layer_mode_blend_luminance (GeglOperation *operation, gfloat *comp, gint samples) { - const Babl *fish; - gfloat *scratch; - gfloat *in_Y; - gfloat *layer_Y; - const Babl *space = gegl_operation_get_source_space (operation, "input"); + static const Babl *fish; + gfloat *scratch; + gfloat *in_Y; + gfloat *layer_Y; + const Babl *format = gegl_operation_get_source_format (operation, "input"); + const Babl *space = gegl_operation_get_source_space (operation, "input"); fish = babl_fish (babl_format_with_space ("RGBA float", space), - babl_format_with_space ("Y float", space)); + babl_format_with_space ("Y float", space)); scratch = gegl_scratch_new (gfloat, 2 * samples);