[gimp] app: add darken only, lighten only that uses luminance
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add darken only, lighten only that uses luminance
- Date: Sun, 29 Jan 2017 21:28:07 +0000 (UTC)
commit e9a6d93197d49675713f9e5936df37378f4f864c
Author: Øyvind Kolås <pippin gimp org>
Date: Sat Jan 28 21:18:51 2017 +0100
app: add darken only, lighten only that uses luminance
These variations on darken only and lighten only have the advantage over the
componentvise versions that they always use the full triplet of either original
or new layer - meaning no new colors/hues will be introduced. This is similar
to how these modes operated/operates in picture publisher and photo-paint.
app/core/core-enums.c | 4 +
app/core/core-enums.h | 2 +
app/core/gimp-layer-modes.c | 20 ++++++
.../layer-modes/gimpoperationlayermode.c | 66 ++++++++++++++++++++
app/widgets/gimpwidgets-constructors.c | 4 +-
5 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index 6eb7ad0..973b88c 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -360,6 +360,8 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_EXCLUSION_LINEAR, "GIMP_LAYER_MODE_EXCLUSION_LINEAR", "exclusion-linear" },
{ GIMP_LAYER_MODE_LINEAR_BURN, "GIMP_LAYER_MODE_LINEAR_BURN", "linear-burn" },
{ GIMP_LAYER_MODE_LINEAR_BURN_LINEAR, "GIMP_LAYER_MODE_LINEAR_BURN_LINEAR", "linear-burn-linear" },
+ { GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY, "GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY",
"luminance-darken-only" },
+ { GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY, "GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY",
"luminance-lighten-only" },
{ GIMP_LAYER_MODE_ERASE, "GIMP_LAYER_MODE_ERASE", "erase" },
{ GIMP_LAYER_MODE_REPLACE, "GIMP_LAYER_MODE_REPLACE", "replace" },
{ GIMP_LAYER_MODE_ANTI_ERASE, "GIMP_LAYER_MODE_ANTI_ERASE", "anti-erase" },
@@ -439,6 +441,8 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_EXCLUSION_LINEAR, NC_("layer-mode", "Exclusion (linear)"), NULL },
{ GIMP_LAYER_MODE_LINEAR_BURN, NC_("layer-mode", "Linear burn"), NULL },
{ GIMP_LAYER_MODE_LINEAR_BURN_LINEAR, NC_("layer-mode", "Linear burn (linear)"), NULL },
+ { GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY, NC_("layer-mode", "Luminance darken only"), NULL },
+ { GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY, NC_("layer-mode", "Luminance lighten only"), NULL },
{ GIMP_LAYER_MODE_ERASE, NC_("layer-mode", "Erase"), NULL },
{ GIMP_LAYER_MODE_REPLACE, NC_("layer-mode", "Replace"), NULL },
{ GIMP_LAYER_MODE_ANTI_ERASE, NC_("layer-mode", "Anti erase"), NULL },
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index 68337da..a6f39c5 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -230,6 +230,8 @@ typedef enum
GIMP_LAYER_MODE_EXCLUSION_LINEAR, /*< desc="Exclusion (linear)" >*/
GIMP_LAYER_MODE_LINEAR_BURN, /*< desc="Linear burn" >*/
GIMP_LAYER_MODE_LINEAR_BURN_LINEAR, /*< desc="Linear burn (linear)" >*/
+ GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY, /*< desc="Luminance darken only" >*/
+ GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY,/*< desc="Luminance lighten only" >*/
/* Internal modes, not available to the PDB */
GIMP_LAYER_MODE_ERASE = 1000, /*< pdb-skip, desc="Erase" >*/
diff --git a/app/core/gimp-layer-modes.c b/app/core/gimp-layer-modes.c
index adbd770..fb48313 100644
--- a/app/core/gimp-layer-modes.c
+++ b/app/core/gimp-layer-modes.c
@@ -118,6 +118,8 @@ gimp_layer_mode_is_linear (GimpLayerMode mode)
case GIMP_LAYER_MODE_SUBTRACT:
case GIMP_LAYER_MODE_DARKEN_ONLY:
case GIMP_LAYER_MODE_LIGHTEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY:
case GIMP_LAYER_MODE_HSV_HUE:
case GIMP_LAYER_MODE_HSV_SATURATION:
case GIMP_LAYER_MODE_HSV_COLOR:
@@ -246,6 +248,8 @@ gimp_layer_mode_get_blend_space (GimpLayerMode mode)
case GIMP_LAYER_MODE_SUBTRACT_LINEAR:
case GIMP_LAYER_MODE_DARKEN_ONLY:
case GIMP_LAYER_MODE_LIGHTEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY:
case GIMP_LAYER_MODE_DIVIDE_LINEAR:
case GIMP_LAYER_MODE_DODGE_LINEAR:
case GIMP_LAYER_MODE_BURN_LINEAR:
@@ -325,6 +329,8 @@ gimp_layer_mode_get_composite_mode (GimpLayerMode mode)
case GIMP_LAYER_MODE_SUBTRACT_LINEAR:
case GIMP_LAYER_MODE_DARKEN_ONLY:
case GIMP_LAYER_MODE_LIGHTEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY:
+ case GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY:
case GIMP_LAYER_MODE_HSV_HUE:
case GIMP_LAYER_MODE_HSV_SATURATION:
case GIMP_LAYER_MODE_HSV_COLOR:
@@ -677,6 +683,20 @@ gimp_layer_mode_get_for_group (GimpLayerMode old_mode,
},
{
+ GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY,
+ GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY,
+ GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY,
+ -1
+ },
+
+ {
+ GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY,
+ GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY,
+ GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY,
+ -1
+ },
+
+ {
GIMP_LAYER_MODE_ERASE,
GIMP_LAYER_MODE_ERASE,
-1,
diff --git a/app/operations/layer-modes/gimpoperationlayermode.c
b/app/operations/layer-modes/gimpoperationlayermode.c
index 6207ff9..1189f27 100644
--- a/app/operations/layer-modes/gimpoperationlayermode.c
+++ b/app/operations/layer-modes/gimpoperationlayermode.c
@@ -985,6 +985,70 @@ blendfun_darken_only (const float *dest,
}
static inline void
+blendfun_luminance_lighten_only (const float *dest,
+ const float *src,
+ float *out,
+ int samples)
+{
+ while (samples--)
+ {
+ if (dest[ALPHA] != 0.0f && src[ALPHA] != 0.0f)
+ {
+ gint c;
+ float dest_luminance =
+ GIMP_RGB_LUMINANCE(dest[0], dest[1], dest[2]);
+ float src_luminance =
+ GIMP_RGB_LUMINANCE(src[0], src[1], src[2]);
+
+ if (dest_luminance >= src_luminance)
+ for (c = 0; c < 3; c++)
+ out[c] = dest[c];
+ else
+ for (c = 0; c < 3; c++)
+ out[c] = src[c];
+ }
+
+ out[ALPHA] = src[ALPHA];
+
+ out += 4;
+ src += 4;
+ dest += 4;
+ }
+}
+
+static inline void
+blendfun_luminance_darken_only (const float *dest,
+ const float *src,
+ float *out,
+ int samples)
+{
+ while (samples--)
+ {
+ if (dest[ALPHA] != 0.0f && src[ALPHA] != 0.0f)
+ {
+ gint c;
+ float dest_luminance =
+ GIMP_RGB_LUMINANCE(dest[0], dest[1], dest[2]);
+ float src_luminance =
+ GIMP_RGB_LUMINANCE(src[0], src[1], src[2]);
+
+ if (dest_luminance <= src_luminance)
+ for (c = 0; c < 3; c++)
+ out[c] = dest[c];
+ else
+ for (c = 0; c < 3; c++)
+ out[c] = src[c];
+ }
+
+ out[ALPHA] = src[ALPHA];
+
+ out += 4;
+ src += 4;
+ dest += 4;
+ }
+}
+
+static inline void
blendfun_lighten_only (const float *dest,
const float *src,
float *out,
@@ -1717,6 +1781,8 @@ static inline GimpBlendFunc gimp_layer_mode_get_blend_fun (GimpLayerMode mode)
case GIMP_LAYER_MODE_DIFFERENCE: return blendfun_difference;
case GIMP_LAYER_MODE_DARKEN_ONLY: return blendfun_darken_only;
case GIMP_LAYER_MODE_LIGHTEN_ONLY: return blendfun_lighten_only;
+ case GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY: return blendfun_luminance_darken_only;
+ case GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY: return blendfun_luminance_lighten_only;
case GIMP_LAYER_MODE_VIVID_LIGHT_LINEAR:
case GIMP_LAYER_MODE_VIVID_LIGHT: return blendfun_vivid_light;
case GIMP_LAYER_MODE_PIN_LIGHT_LINEAR:
diff --git a/app/widgets/gimpwidgets-constructors.c b/app/widgets/gimpwidgets-constructors.c
index 699b4b5..019605e 100644
--- a/app/widgets/gimpwidgets-constructors.c
+++ b/app/widgets/gimpwidgets-constructors.c
@@ -104,12 +104,13 @@ gimp_paint_mode_menu_new (gboolean with_behind_mode,
GtkWidget *combo;
store = gimp_enum_store_new_with_values (GIMP_TYPE_LAYER_MODE,
- 45,
+ 47,
GIMP_LAYER_MODE_NORMAL,
GIMP_LAYER_MODE_NORMAL_LINEAR,
GIMP_LAYER_MODE_DISSOLVE,
GIMP_LAYER_MODE_LIGHTEN_ONLY,
GIMP_LAYER_MODE_LIGHTEN_ONLY_LEGACY,
+ GIMP_LAYER_MODE_LUMINANCE_LIGHTEN_ONLY,
GIMP_LAYER_MODE_SCREEN,
GIMP_LAYER_MODE_SCREEN_LEGACY,
GIMP_LAYER_MODE_DODGE,
@@ -118,6 +119,7 @@ gimp_paint_mode_menu_new (gboolean with_behind_mode,
GIMP_LAYER_MODE_ADDITION_LEGACY,
GIMP_LAYER_MODE_DARKEN_ONLY,
GIMP_LAYER_MODE_DARKEN_ONLY_LEGACY,
+ GIMP_LAYER_MODE_LUMINANCE_DARKEN_ONLY,
GIMP_LAYER_MODE_MULTIPLY,
GIMP_LAYER_MODE_MULTIPLY_LINEAR,
GIMP_LAYER_MODE_MULTIPLY_LEGACY,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]