[gimp] app: implement color-erase mode as a GimpOperationLayerMode blendfun
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: implement color-erase mode as a GimpOperationLayerMode blendfun
- Date: Wed, 8 Mar 2017 19:19:05 +0000 (UTC)
commit b22c09e7b77ae0b957d17e818edba9b68f637289
Author: Ell <ell_se yahoo com>
Date: Wed Mar 8 13:06:46 2017 -0500
app: implement color-erase mode as a GimpOperationLayerMode blendfun
... and get rid of the dedicated op. This gives us support for all
the blend/composite options for this mode.
Rename COLOR_ERASE to COLOR_ERASE_LEGACY, with perceptual blending/
compositing and immutable everything, and add a new COLOR_ERASE
mode, defaulting to linear blending/compositing, with mutable
everything. Modify affected code.
app/core/gimpimage.c | 3 +-
app/operations/gimp-operations.c | 2 -
app/operations/layer-modes/Makefile.am | 2 -
app/operations/layer-modes/gimp-layer-modes.c | 26 +++-
.../layer-modes/gimpoperationcolorerase.c | 167 --------------------
.../layer-modes/gimpoperationcolorerase.h | 62 -------
.../layer-modes/gimpoperationlayermode.c | 61 +++++++-
app/operations/operations-enums.c | 6 +-
app/operations/operations-enums.h | 3 +-
libgimp/gimpenums.h | 5 +-
libgimp/gimptypes.h | 2 +-
plug-ins/file-psd/psd-util.c | 3 +-
tools/pdbgen/enums.pl | 10 +-
13 files changed, 100 insertions(+), 252 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index f4d3709..14517a0 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -2419,7 +2419,7 @@ gimp_image_get_xcf_version (GimpImage *image,
case GIMP_LAYER_MODE_SOFTLIGHT_LEGACY:
case GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY:
case GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY:
- case GIMP_LAYER_MODE_COLOR_ERASE:
+ case GIMP_LAYER_MODE_COLOR_ERASE_LEGACY:
version = MAX (2, version);
break;
@@ -2462,6 +2462,7 @@ gimp_image_get_xcf_version (GimpImage *image,
case GIMP_LAYER_MODE_LUMA_DARKEN_ONLY:
case GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY:
case GIMP_LAYER_MODE_LUMINANCE:
+ case GIMP_LAYER_MODE_COLOR_ERASE:
version = MAX (10, version);
break;
diff --git a/app/operations/gimp-operations.c b/app/operations/gimp-operations.c
index 1149e7d..93c7be2 100644
--- a/app/operations/gimp-operations.c
+++ b/app/operations/gimp-operations.c
@@ -87,7 +87,6 @@
#include "layer-modes/gimpoperationantierase.h"
#include "layer-modes/gimpoperationbehind.h"
#include "layer-modes/gimpoperationerase.h"
-#include "layer-modes/gimpoperationcolorerase.h"
#include "layer-modes/gimpoperationdissolve.h"
#include "layer-modes/gimpoperationnormal.h"
#include "layer-modes/gimpoperationreplace.h"
@@ -147,7 +146,6 @@ gimp_operations_init (void)
g_type_class_ref (GIMP_TYPE_OPERATION_SOFTLIGHT_LEGACY);
g_type_class_ref (GIMP_TYPE_OPERATION_GRAIN_EXTRACT_LEGACY);
g_type_class_ref (GIMP_TYPE_OPERATION_GRAIN_MERGE_LEGACY);
- g_type_class_ref (GIMP_TYPE_OPERATION_COLOR_ERASE);
g_type_class_ref (GIMP_TYPE_OPERATION_ERASE);
g_type_class_ref (GIMP_TYPE_OPERATION_REPLACE);
g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE);
diff --git a/app/operations/layer-modes/Makefile.am b/app/operations/layer-modes/Makefile.am
index 0c12c31..f0852e7 100644
--- a/app/operations/layer-modes/Makefile.am
+++ b/app/operations/layer-modes/Makefile.am
@@ -29,8 +29,6 @@ libapplayermodes_generic_a_sources = \
gimpoperationantierase.h \
gimpoperationbehind.c \
gimpoperationbehind.h \
- gimpoperationcolorerase.c \
- gimpoperationcolorerase.h \
gimpoperationdissolve.c \
gimpoperationdissolve.h \
gimpoperationerase.c \
diff --git a/app/operations/layer-modes/gimp-layer-modes.c b/app/operations/layer-modes/gimp-layer-modes.c
index 485554e..a71af12 100644
--- a/app/operations/layer-modes/gimp-layer-modes.c
+++ b/app/operations/layer-modes/gimp-layer-modes.c
@@ -46,7 +46,6 @@
#include "gimpoperationantierase.h"
#include "gimpoperationbehind.h"
-#include "gimpoperationcolorerase.h"
#include "gimpoperationdissolve.h"
#include "gimpoperationerase.h"
#include "gimpoperationnormal.h"
@@ -399,11 +398,12 @@ static const GimpLayerModeInfo layer_mode_infos[] =
.blend_space = GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL
},
- { GIMP_LAYER_MODE_COLOR_ERASE,
+ { GIMP_LAYER_MODE_COLOR_ERASE_LEGACY,
- .op_name = "gimp:color-erase",
- .function = gimp_operation_color_erase_process,
- .flags = GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE |
+ .op_name = "gimp:layer-mode",
+ .function = gimp_operation_layer_mode_process_pixels,
+ .flags = GIMP_LAYER_MODE_FLAG_LEGACY |
+ GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE |
GIMP_LAYER_MODE_FLAG_COMPOSITE_SPACE_IMMUTABLE |
GIMP_LAYER_MODE_FLAG_COMPOSITE_MODE_IMMUTABLE |
GIMP_LAYER_MODE_FLAG_SUBTRACTIVE,
@@ -801,6 +801,19 @@ static const GimpLayerModeInfo layer_mode_infos[] =
.blend_space = GIMP_LAYER_COLOR_SPACE_RGB_LINEAR
},
+ { GIMP_LAYER_MODE_COLOR_ERASE,
+
+ .op_name = "gimp:layer-mode",
+ .function = gimp_operation_layer_mode_process_pixels,
+ .flags = GIMP_LAYER_MODE_FLAG_SUBTRACTIVE,
+ .context = GIMP_LAYER_MODE_CONTEXT_PAINT |
+ GIMP_LAYER_MODE_CONTEXT_FADE,
+ .paint_composite_mode = GIMP_LAYER_COMPOSITE_SRC_ATOP,
+ .composite_mode = GIMP_LAYER_COMPOSITE_SRC_ATOP,
+ .composite_space = GIMP_LAYER_COLOR_SPACE_RGB_LINEAR,
+ .blend_space = GIMP_LAYER_COLOR_SPACE_RGB_LINEAR
+ },
+
{ GIMP_LAYER_MODE_ERASE,
.op_name = "gimp:erase",
@@ -905,6 +918,7 @@ static const GimpLayerMode layer_mode_group_legacy[] =
GIMP_LAYER_MODE_NORMAL_LEGACY,
GIMP_LAYER_MODE_DISSOLVE,
GIMP_LAYER_MODE_BEHIND_LEGACY,
+ GIMP_LAYER_MODE_COLOR_ERASE_LEGACY,
GIMP_LAYER_MODE_SEPARATOR,
@@ -1032,7 +1046,7 @@ static const GimpLayerMode layer_mode_groups[][2] =
},
{ [GIMP_LAYER_MODE_GROUP_DEFAULT] = GIMP_LAYER_MODE_COLOR_ERASE,
- [GIMP_LAYER_MODE_GROUP_LEGACY ] = -1,
+ [GIMP_LAYER_MODE_GROUP_LEGACY ] = GIMP_LAYER_MODE_COLOR_ERASE_LEGACY,
},
{ [GIMP_LAYER_MODE_GROUP_DEFAULT] = GIMP_LAYER_MODE_VIVID_LIGHT,
diff --git a/app/operations/layer-modes/gimpoperationlayermode.c
b/app/operations/layer-modes/gimpoperationlayermode.c
index f53f1b0..d4ecfe7 100644
--- a/app/operations/layer-modes/gimpoperationlayermode.c
+++ b/app/operations/layer-modes/gimpoperationlayermode.c
@@ -2149,6 +2149,64 @@ blendfun_exclusion (const float *dest,
}
static inline void
+blendfun_color_erase (const float *dest,
+ const float *src,
+ float *out,
+ int samples)
+{
+ while (samples--)
+ {
+ if (dest[ALPHA] != 0.0f && src[ALPHA] != 0.0f)
+ {
+ const float *color = dest;
+ const float *bgcolor = src;
+ gfloat alpha;
+ gint c;
+
+ alpha = 0.0f;
+
+ for (c = 0; c < 3; c++)
+ {
+ gfloat col = CLAMP (color[c], 0.0f, 1.0f);
+ gfloat bgcol = CLAMP (bgcolor[c], 0.0f, 1.0f);
+
+ if (col != bgcol)
+ {
+ gfloat a;
+
+ if (col > bgcol)
+ a = (col - bgcol) / (1.0f - bgcol);
+ else
+ a = (bgcol - col) / bgcol;
+
+ alpha = MAX (alpha, a);
+ }
+ }
+
+ if (alpha > 0.0f)
+ {
+ gfloat alpha_inv = 1.0f / alpha;
+
+ for (c = 0; c < 3; c++)
+ out[c] = (color[c] - bgcolor[c]) * alpha_inv + bgcolor[c];
+ }
+ else
+ {
+ out[RED] = out[GREEN] = out[BLUE] = 0.0f;
+ }
+
+ out[ALPHA] = alpha;
+ }
+ else
+ out[ALPHA] = 0.0f;
+
+ out += 4;
+ src += 4;
+ dest += 4;
+ }
+}
+
+static inline void
blendfun_dummy (const float *dest,
const float *src,
float *out,
@@ -2195,6 +2253,8 @@ gimp_layer_mode_get_blend_fun (GimpLayerMode mode)
case GIMP_LAYER_MODE_HARD_MIX: return blendfun_hard_mix;
case GIMP_LAYER_MODE_EXCLUSION: return blendfun_exclusion;
case GIMP_LAYER_MODE_LINEAR_BURN: return blendfun_linear_burn;
+ case GIMP_LAYER_MODE_COLOR_ERASE_LEGACY:
+ case GIMP_LAYER_MODE_COLOR_ERASE: return blendfun_color_erase;
case GIMP_LAYER_MODE_DISSOLVE:
case GIMP_LAYER_MODE_BEHIND_LEGACY:
@@ -2218,7 +2278,6 @@ gimp_layer_mode_get_blend_fun (GimpLayerMode mode)
case GIMP_LAYER_MODE_SOFTLIGHT_LEGACY:
case GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY:
case GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY:
- case GIMP_LAYER_MODE_COLOR_ERASE:
case GIMP_LAYER_MODE_ERASE:
case GIMP_LAYER_MODE_REPLACE:
case GIMP_LAYER_MODE_ANTI_ERASE:
diff --git a/app/operations/operations-enums.c b/app/operations/operations-enums.c
index d331cc0..5dfec3a 100644
--- a/app/operations/operations-enums.c
+++ b/app/operations/operations-enums.c
@@ -103,7 +103,7 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_SOFTLIGHT_LEGACY, "GIMP_LAYER_MODE_SOFTLIGHT_LEGACY", "softlight-legacy" },
{ GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY, "GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY", "grain-extract-legacy" },
{ GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY, "GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY", "grain-merge-legacy" },
- { GIMP_LAYER_MODE_COLOR_ERASE, "GIMP_LAYER_MODE_COLOR_ERASE", "color-erase" },
+ { GIMP_LAYER_MODE_COLOR_ERASE_LEGACY, "GIMP_LAYER_MODE_COLOR_ERASE_LEGACY", "color-erase-legacy" },
{ GIMP_LAYER_MODE_OVERLAY, "GIMP_LAYER_MODE_OVERLAY", "overlay" },
{ GIMP_LAYER_MODE_LCH_HUE, "GIMP_LAYER_MODE_LCH_HUE", "lch-hue" },
{ GIMP_LAYER_MODE_LCH_CHROMA, "GIMP_LAYER_MODE_LCH_CHROMA", "lch-chroma" },
@@ -138,6 +138,7 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_LUMA_DARKEN_ONLY, "GIMP_LAYER_MODE_LUMA_DARKEN_ONLY", "luma-darken-only" },
{ GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY, "GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY", "luma-lighten-only" },
{ GIMP_LAYER_MODE_LUMINANCE, "GIMP_LAYER_MODE_LUMINANCE", "luminance" },
+ { GIMP_LAYER_MODE_COLOR_ERASE, "GIMP_LAYER_MODE_COLOR_ERASE", "color-erase" },
{ 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" },
@@ -168,7 +169,7 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_SOFTLIGHT_LEGACY, NC_("layer-mode", "Soft light (legacy)"), NULL },
{ GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY, NC_("layer-mode", "Grain extract (legacy)"), NULL },
{ GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY, NC_("layer-mode", "Grain merge (legacy)"), NULL },
- { GIMP_LAYER_MODE_COLOR_ERASE, NC_("layer-mode", "Color erase"), NULL },
+ { GIMP_LAYER_MODE_COLOR_ERASE_LEGACY, NC_("layer-mode", "Color erase (legacy)"), NULL },
{ GIMP_LAYER_MODE_OVERLAY, NC_("layer-mode", "Overlay"), NULL },
{ GIMP_LAYER_MODE_LCH_HUE, NC_("layer-mode", "Hue (LCH)"), NULL },
{ GIMP_LAYER_MODE_LCH_CHROMA, NC_("layer-mode", "Chroma (LCH)"), NULL },
@@ -203,6 +204,7 @@ gimp_layer_mode_get_type (void)
{ GIMP_LAYER_MODE_LUMA_DARKEN_ONLY, NC_("layer-mode", "Luma/Luminance darken only"), NULL },
{ GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY, NC_("layer-mode", "Luma/Luminance lighten only"), NULL },
{ GIMP_LAYER_MODE_LUMINANCE, NC_("layer-mode", "Luminance"), NULL },
+ { GIMP_LAYER_MODE_COLOR_ERASE, NC_("layer-mode", "Color erase"), 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/operations/operations-enums.h b/app/operations/operations-enums.h
index c5bf617..e8d9ae3 100644
--- a/app/operations/operations-enums.h
+++ b/app/operations/operations-enums.h
@@ -77,7 +77,7 @@ typedef enum
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY, /*< desc="Soft light (legacy)" >*/
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY, /*< desc="Grain extract (legacy)" >*/
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY, /*< desc="Grain merge (legacy)" >*/
- GIMP_LAYER_MODE_COLOR_ERASE, /*< desc="Color erase" >*/
+ GIMP_LAYER_MODE_COLOR_ERASE_LEGACY, /*< desc="Color erase (legacy)" >*/
/* Since 2.8 */
GIMP_LAYER_MODE_OVERLAY, /*< desc="Overlay" >*/
@@ -116,6 +116,7 @@ typedef enum
GIMP_LAYER_MODE_LUMA_DARKEN_ONLY, /*< desc="Luma/Luminance darken only" >*/
GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY, /*< desc="Luma/Luminance lighten only" >*/
GIMP_LAYER_MODE_LUMINANCE, /*< desc="Luminance" >*/
+ GIMP_LAYER_MODE_COLOR_ERASE, /*< desc="Color erase" >*/
/* Internal modes, not available to the PDB, must be kept at the end */
GIMP_LAYER_MODE_ERASE, /*< pdb-skip, desc="Erase" >*/
diff --git a/libgimp/gimpenums.h b/libgimp/gimpenums.h
index 58df15f..b80395b 100644
--- a/libgimp/gimpenums.h
+++ b/libgimp/gimpenums.h
@@ -117,7 +117,7 @@ typedef enum
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY,
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY,
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY,
- GIMP_LAYER_MODE_COLOR_ERASE,
+ GIMP_LAYER_MODE_COLOR_ERASE_LEGACY,
GIMP_LAYER_MODE_OVERLAY,
GIMP_LAYER_MODE_LCH_HUE,
GIMP_LAYER_MODE_LCH_CHROMA,
@@ -151,7 +151,8 @@ typedef enum
GIMP_LAYER_MODE_LINEAR_BURN,
GIMP_LAYER_MODE_LUMA_DARKEN_ONLY,
GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY,
- GIMP_LAYER_MODE_LUMINANCE
+ GIMP_LAYER_MODE_LUMINANCE,
+ GIMP_LAYER_MODE_COLOR_ERASE
} GimpLayerMode;
diff --git a/libgimp/gimptypes.h b/libgimp/gimptypes.h
index d8eee1d..a7b8a5c 100644
--- a/libgimp/gimptypes.h
+++ b/libgimp/gimptypes.h
@@ -68,7 +68,7 @@ typedef GimpLayerMode GimpLayerModeEffects;
#define GIMP_SOFTLIGHT_MODE GIMP_LAYER_MODE_SOFTLIGHT_LEGACY
#define GIMP_GRAIN_EXTRACT_MODE GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY
#define GIMP_GRAIN_MERGE_MODE GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY
-#define GIMP_COLOR_ERASE_MODE GIMP_LAYER_MODE_COLOR_ERASE
+#define GIMP_COLOR_ERASE_MODE GIMP_LAYER_MODE_COLOR_ERASE_LEGACY
#define GIMP_NO_DITHER GIMP_CONVERT_DITHER_NONE
#define GIMP_FS_DITHER GIMP_CONVERT_DITHER_FS
diff --git a/plug-ins/file-psd/psd-util.c b/plug-ins/file-psd/psd-util.c
index 7cfbe3e..f5096dd 100644
--- a/plug-ins/file-psd/psd-util.c
+++ b/plug-ins/file-psd/psd-util.c
@@ -933,6 +933,7 @@ gimp_to_psd_blend_mode (GimpLayerMode layer_mode,
break;
case GIMP_LAYER_MODE_COLOR_ERASE:
+ case GIMP_LAYER_MODE_COLOR_ERASE_LEGACY:
if (CONVERSION_WARNINGS)
g_message ("Unsupported blend mode: %s. Mode reverts to normal",
gimp_layer_mode_effects_name (layer_mode));
@@ -985,7 +986,7 @@ gimp_layer_mode_effects_name (GimpLayerMode mode)
"COLOR ERASE"
};
static gchar *err_name = NULL;
- if (mode >= 0 && mode <= GIMP_LAYER_MODE_COLOR_ERASE)
+ if (mode >= 0 && mode <= GIMP_LAYER_MODE_COLOR_ERASE_LEGACY)
return layer_mode_effects_names[mode];
g_free (err_name);
diff --git a/tools/pdbgen/enums.pl b/tools/pdbgen/enums.pl
index 66da9d4..4edf222 100644
--- a/tools/pdbgen/enums.pl
+++ b/tools/pdbgen/enums.pl
@@ -719,7 +719,7 @@ package Gimp::CodeGen::enums;
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY
- GIMP_LAYER_MODE_COLOR_ERASE
+ GIMP_LAYER_MODE_COLOR_ERASE_LEGACY
GIMP_LAYER_MODE_OVERLAY GIMP_LAYER_MODE_LCH_HUE
GIMP_LAYER_MODE_LCH_CHROMA
GIMP_LAYER_MODE_LCH_COLOR
@@ -746,7 +746,8 @@ package Gimp::CodeGen::enums;
GIMP_LAYER_MODE_LINEAR_BURN
GIMP_LAYER_MODE_LUMA_DARKEN_ONLY
GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY
- GIMP_LAYER_MODE_LUMINANCE) ],
+ GIMP_LAYER_MODE_LUMINANCE
+ GIMP_LAYER_MODE_COLOR_ERASE) ],
mapping => { GIMP_LAYER_MODE_NORMAL_LEGACY => '0',
GIMP_LAYER_MODE_DISSOLVE => '1',
GIMP_LAYER_MODE_BEHIND_LEGACY => '2',
@@ -769,7 +770,7 @@ package Gimp::CodeGen::enums;
GIMP_LAYER_MODE_SOFTLIGHT_LEGACY => '19',
GIMP_LAYER_MODE_GRAIN_EXTRACT_LEGACY => '20',
GIMP_LAYER_MODE_GRAIN_MERGE_LEGACY => '21',
- GIMP_LAYER_MODE_COLOR_ERASE => '22',
+ GIMP_LAYER_MODE_COLOR_ERASE_LEGACY => '22',
GIMP_LAYER_MODE_OVERLAY => '23',
GIMP_LAYER_MODE_LCH_HUE => '24',
GIMP_LAYER_MODE_LCH_CHROMA => '25',
@@ -803,7 +804,8 @@ package Gimp::CodeGen::enums;
GIMP_LAYER_MODE_LINEAR_BURN => '53',
GIMP_LAYER_MODE_LUMA_DARKEN_ONLY => '54',
GIMP_LAYER_MODE_LUMA_LIGHTEN_ONLY => '55',
- GIMP_LAYER_MODE_LUMINANCE => '56' }
+ GIMP_LAYER_MODE_LUMINANCE => '56',
+ GIMP_LAYER_MODE_COLOR_ERASE => '57' }
},
GimpConvertDitherType =>
{ contig => 1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]