Commit bc4cf991 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

Bug 673501 - Issue with Overlay

GIMP's OVERLAY mode was identical to SOFTLIGHT. This commit fixes the
issue and introduces a NEW_OVERLAY mode and enum value.

- change gimp:overlay-mode to be a real (svg-ish) overlay mode
- when compositing, map OVERLAY to gimp:softlight-mode
- when compisiting, map NEW_OVERLAY to gimp:overlay-mode
- bump the XCF version when NEW_OVERLAY is used
- map OVERLAY to SOFTLIGHT when loading and saving XCF
- map OVERLAY to softlight in all PDB setters
- map OVERLAY to softlight when deserializing a GimpContext
- change all paint mode menus to show an entry for NEW_OVERLAY
  instead of OVERLAY
- change PSP, PSD and OpenRaster to use NEW_OVERLAY

These changes should (redundantly) make sure that no OVERLAY enum
value is used in the core any longer because it gets mapped to
SOFTLIGHT at all entry points, with the downside of introducing a
setter/getter asymmetry when OVERLAY was set in a PDB api.
parent 47c31a91
......@@ -57,7 +57,7 @@ static const GimpLayerModeEffects paint_modes[] =
GIMP_MULTIPLY_MODE,
GIMP_DIVIDE_MODE,
GIMP_SCREEN_MODE,
GIMP_OVERLAY_MODE,
GIMP_NEW_OVERLAY_MODE,
GIMP_DODGE_MODE,
GIMP_BURN_MODE,
GIMP_HARDLIGHT_MODE,
......
......@@ -82,7 +82,7 @@ static const GimpLayerModeEffects layer_modes[] =
GIMP_MULTIPLY_MODE,
GIMP_DIVIDE_MODE,
GIMP_SCREEN_MODE,
GIMP_OVERLAY_MODE,
GIMP_NEW_OVERLAY_MODE,
GIMP_DODGE_MODE,
GIMP_BURN_MODE,
GIMP_HARDLIGHT_MODE,
......
......@@ -275,6 +275,7 @@ gimp_layer_mode_effects_get_type (void)
{ GIMP_GRAIN_EXTRACT_MODE, "GIMP_GRAIN_EXTRACT_MODE", "grain-extract-mode" },
{ GIMP_GRAIN_MERGE_MODE, "GIMP_GRAIN_MERGE_MODE", "grain-merge-mode" },
{ GIMP_COLOR_ERASE_MODE, "GIMP_COLOR_ERASE_MODE", "color-erase-mode" },
{ GIMP_NEW_OVERLAY_MODE, "GIMP_NEW_OVERLAY_MODE", "new-overlay-mode" },
{ GIMP_ERASE_MODE, "GIMP_ERASE_MODE", "erase-mode" },
{ GIMP_REPLACE_MODE, "GIMP_REPLACE_MODE", "replace-mode" },
{ GIMP_ANTI_ERASE_MODE, "GIMP_ANTI_ERASE_MODE", "anti-erase-mode" },
......@@ -288,7 +289,7 @@ gimp_layer_mode_effects_get_type (void)
{ GIMP_BEHIND_MODE, NC_("layer-mode-effects", "Behind"), NULL },
{ GIMP_MULTIPLY_MODE, NC_("layer-mode-effects", "Multiply"), NULL },
{ GIMP_SCREEN_MODE, NC_("layer-mode-effects", "Screen"), NULL },
{ GIMP_OVERLAY_MODE, NC_("layer-mode-effects", "Overlay"), NULL },
{ GIMP_OVERLAY_MODE, NC_("layer-mode-effects", "Old broken Overlay"), NULL },
{ GIMP_DIFFERENCE_MODE, NC_("layer-mode-effects", "Difference"), NULL },
{ GIMP_ADDITION_MODE, NC_("layer-mode-effects", "Addition"), NULL },
{ GIMP_SUBTRACT_MODE, NC_("layer-mode-effects", "Subtract"), NULL },
......@@ -306,6 +307,7 @@ gimp_layer_mode_effects_get_type (void)
{ GIMP_GRAIN_EXTRACT_MODE, NC_("layer-mode-effects", "Grain extract"), NULL },
{ GIMP_GRAIN_MERGE_MODE, NC_("layer-mode-effects", "Grain merge"), NULL },
{ GIMP_COLOR_ERASE_MODE, NC_("layer-mode-effects", "Color erase"), NULL },
{ GIMP_NEW_OVERLAY_MODE, NC_("layer-mode-effects", "Overlay"), NULL },
{ GIMP_ERASE_MODE, NC_("layer-mode-effects", "Erase"), NULL },
{ GIMP_REPLACE_MODE, NC_("layer-mode-effects", "Replace"), NULL },
{ GIMP_ANTI_ERASE_MODE, NC_("layer-mode-effects", "Anti erase"), NULL },
......
......@@ -144,7 +144,7 @@ typedef enum
GIMP_BEHIND_MODE, /*< desc="Behind" >*/
GIMP_MULTIPLY_MODE, /*< desc="Multiply" >*/
GIMP_SCREEN_MODE, /*< desc="Screen" >*/
GIMP_OVERLAY_MODE, /*< desc="Overlay" >*/
GIMP_OVERLAY_MODE, /*< desc="Old broken Overlay" >*/
GIMP_DIFFERENCE_MODE, /*< desc="Difference" >*/
GIMP_ADDITION_MODE, /*< desc="Addition" >*/
GIMP_SUBTRACT_MODE, /*< desc="Subtract" >*/
......@@ -162,6 +162,7 @@ typedef enum
GIMP_GRAIN_EXTRACT_MODE, /*< desc="Grain extract" >*/
GIMP_GRAIN_MERGE_MODE, /*< desc="Grain merge" >*/
GIMP_COLOR_ERASE_MODE, /*< desc="Color erase" >*/
GIMP_NEW_OVERLAY_MODE, /*< desc="Overlay" >*/
/* internal modes, not available to the PDB */
GIMP_ERASE_MODE = 1000, /*< pdb-skip, desc="Erase" >*/
......
......@@ -86,6 +86,10 @@ static gint64 gimp_context_get_memsize (GimpObject *object,
static gboolean gimp_context_serialize (GimpConfig *config,
GimpConfigWriter *writer,
gpointer data);
static gboolean gimp_context_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_context_serialize_property (GimpConfig *config,
guint property_id,
const GValue *value,
......@@ -777,6 +781,7 @@ static void
gimp_context_config_iface_init (GimpConfigInterface *iface)
{
iface->serialize = gimp_context_serialize;
iface->deserialize = gimp_context_deserialize;
iface->serialize_property = gimp_context_serialize_property;
iface->deserialize_property = gimp_context_deserialize_property;
}
......@@ -1251,6 +1256,27 @@ gimp_context_serialize (GimpConfig *config,
return gimp_config_serialize_changed_properties (config, writer);
}
static gboolean
gimp_context_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data)
{
GimpContext *context = GIMP_CONTEXT (config);
GimpLayerModeEffects old_paint_mode = context->paint_mode;
gboolean success;
success = gimp_config_deserialize_properties (config, scanner, nest_level);
if (context->paint_mode != old_paint_mode)
{
if (context->paint_mode == GIMP_OVERLAY_MODE)
g_object_set (context, "paint-mode", GIMP_SOFTLIGHT_MODE, NULL);
}
return success;
}
static gboolean
gimp_context_serialize_property (GimpConfig *config,
guint property_id,
......
......@@ -2315,6 +2315,11 @@ gimp_image_get_xcf_version (GimpImage *image,
version = MAX (2, version);
break;
/* new layer modes not supported by gimp-2.8 */
case GIMP_NEW_OVERLAY_MODE:
version = MAX (9, version);
break;
default:
break;
}
......@@ -2355,6 +2360,7 @@ gimp_image_get_xcf_version (GimpImage *image,
case 6:
case 7:
case 8:
case 9:
if (gimp_version) *gimp_version = 210;
if (version_string) *version_string = "GIMP 2.10";
break;
......
......@@ -155,7 +155,7 @@ gimp_gegl_mode_node_set_mode (GeglNode *node,
case GIMP_BEHIND_MODE: operation = "gimp:behind-mode"; break;
case GIMP_MULTIPLY_MODE: operation = "gimp:multiply-mode"; break;
case GIMP_SCREEN_MODE: operation = "gimp:screen-mode"; break;
case GIMP_OVERLAY_MODE: operation = "gimp:overlay-mode"; break;
case GIMP_OVERLAY_MODE: operation = "gimp:softlight-mode"; break;
case GIMP_DIFFERENCE_MODE: operation = "gimp:difference-mode"; break;
case GIMP_ADDITION_MODE: operation = "gimp:addition-mode"; break;
case GIMP_SUBTRACT_MODE: operation = "gimp:subtract-mode"; break;
......@@ -173,6 +173,7 @@ gimp_gegl_mode_node_set_mode (GeglNode *node,
case GIMP_GRAIN_EXTRACT_MODE: operation = "gimp:grain-extract-mode"; break;
case GIMP_GRAIN_MERGE_MODE: operation = "gimp:grain-merge-mode"; break;
case GIMP_COLOR_ERASE_MODE: operation = "gimp:color-erase-mode"; break;
case GIMP_NEW_OVERLAY_MODE: operation = "gimp:overlay-mode"; break;
case GIMP_ERASE_MODE: operation = "gimp:erase-mode"; break;
case GIMP_REPLACE_MODE: operation = "gimp:replace-mode"; break;
case GIMP_ANTI_ERASE_MODE: operation = "gimp:anti-erase-mode"; break;
......
......@@ -65,7 +65,7 @@ get_layer_mode_function (GimpLayerModeEffects paint_mode)
case GIMP_BEHIND_MODE: func = gimp_operation_behind_mode_process_pixels; break;
case GIMP_MULTIPLY_MODE: func = gimp_operation_multiply_mode_process_pixels; break;
case GIMP_SCREEN_MODE: func = gimp_operation_screen_mode_process_pixels; break;
case GIMP_OVERLAY_MODE: func = gimp_operation_overlay_mode_process_pixels; break;
case GIMP_OVERLAY_MODE: func = gimp_operation_softlight_mode_process_pixels; break;
case GIMP_DIFFERENCE_MODE: func = gimp_operation_difference_mode_process_pixels; break;
case GIMP_ADDITION_MODE: func = gimp_operation_addition_mode_process_pixels; break;
case GIMP_SUBTRACT_MODE: func = gimp_operation_subtract_mode_process_pixels; break;
......@@ -83,6 +83,7 @@ get_layer_mode_function (GimpLayerModeEffects paint_mode)
case GIMP_GRAIN_EXTRACT_MODE: func = gimp_operation_grain_extract_mode_process_pixels; break;
case GIMP_GRAIN_MERGE_MODE: func = gimp_operation_grain_merge_mode_process_pixels; break;
case GIMP_COLOR_ERASE_MODE: func = gimp_operation_color_erase_mode_process_pixels; break;
case GIMP_NEW_OVERLAY_MODE: func = gimp_operation_overlay_mode_process_pixels; break;
case GIMP_ERASE_MODE: func = gimp_operation_erase_mode_process_pixels; break;
case GIMP_REPLACE_MODE: func = gimp_operation_replace_mode_process_pixels; break;
case GIMP_ANTI_ERASE_MODE: func = gimp_operation_anti_erase_mode_process_pixels; break;
......
......@@ -108,7 +108,12 @@ gimp_operation_overlay_mode_process_pixels (gfloat *in,
for (b = RED; b < ALPHA; b++)
{
gfloat comp = in[b] * (in[b] + (2.0 * layer[b]) * (1.0 - in[b]));
gfloat comp;
if (in[b] < 0.5)
comp = 2.0 * in[b] * layer[b];
else
comp = 1.0 - 2.0 * (1.0 - layer[b]) * (1.0 - in[b]);
out[b] = comp * ratio + in[b] * (1.0 - ratio);
}
......
......@@ -126,9 +126,21 @@ gimp_operation_softlight_mode_process_pixels (gfloat *in,
for (b = RED; b < ALPHA; b++)
{
#if 0
/* softlight is now used for what GIMP formerly called
* OVERLAY. We fixed OVERLAY to use the right math
* (under the name NEW_OVERLAY), and redirect uses of
* the old OVERLAY blend mode here. This math was
* formerly used for OVERLAY and is exactly the same as
* the multiply, screen, comp math used below.
* See bug #673501.
*/
gfloat comp = in[b] * (in[b] + (2.0 * layer[b]) * (1.0 - in[b]));
#endif
gfloat multiply = in[b] * layer[b];
gfloat screen = 1.0 - (1.0 - in[b]) * (1.0 - layer[b]);
gfloat comp = (1.0 - in[b]) * multiply + in[b] * screen;
gfloat screen = 1.0 - (1.0 - in[b]) * (1.0 - layer[b]);
gfloat comp = (1.0 - in[b]) * multiply + in[b] * screen;
out[b] = comp * ratio + in[b] * (1.0 - ratio);
}
......
......@@ -61,6 +61,9 @@ brushes_popup_invoker (GimpProcedure *procedure,
if (success)
{
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
if (gimp->no_interface ||
! gimp_pdb_lookup_procedure (gimp->pdb, brush_callback) ||
! gimp_pdb_dialog_new (gimp, context, progress,
......@@ -126,6 +129,9 @@ brushes_set_popup_invoker (GimpProcedure *procedure,
if (success)
{
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
if (gimp->no_interface ||
! gimp_pdb_lookup_procedure (gimp->pdb, brush_callback) ||
! gimp_pdb_dialog_set (gimp, gimp_data_factory_get_container (gimp->brush_factory),
......
......@@ -207,6 +207,9 @@ brushes_get_brush_data_invoker (GimpProcedure *procedure,
{
GimpBrush *brush;
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
if (name && strlen (name))
brush = gimp_pdb_get_brush (gimp, name, FALSE, error);
else
......
......@@ -366,6 +366,9 @@ context_set_paint_mode_invoker (GimpProcedure *procedure,
if (success)
{
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
gimp_context_set_paint_mode (context, paint_mode);
}
......
......@@ -604,6 +604,9 @@ edit_bucket_fill_invoker (GimpProcedure *procedure,
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillType fill_type;
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
switch (fill_mode)
{
default:
......@@ -685,6 +688,9 @@ edit_bucket_fill_full_invoker (GimpProcedure *procedure,
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GimpFillType fill_type;
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
switch (fill_mode)
{
default:
......@@ -788,6 +794,9 @@ edit_blend_invoker (GimpProcedure *procedure,
{
GimpGradient *gradient;
if (paint_mode == GIMP_OVERLAY_MODE)
paint_mode = GIMP_SOFTLIGHT_MODE;
if (progress)
gimp_progress_start (progress, FALSE, _("Blending"));
......
......@@ -83,6 +83,9 @@ layer_new_invoker (GimpProcedure *procedure,
gboolean has_alpha = FALSE;
const Babl *format;
if (mode == GIMP_OVERLAY_MODE)
mode = GIMP_SOFTLIGHT_MODE;
switch (type)
{
case GIMP_RGB_IMAGE:
......@@ -1128,6 +1131,9 @@ layer_set_mode_invoker (GimpProcedure *procedure,
if (success)
{
if (mode == GIMP_OVERLAY_MODE)
mode = GIMP_SOFTLIGHT_MODE;
gimp_layer_set_mode (layer, mode, TRUE);
}
......
......@@ -116,7 +116,7 @@ gimp_paint_mode_menu_new (gboolean with_behind_mode,
GIMP_MULTIPLY_MODE,
GIMP_BURN_MODE,
GIMP_OVERLAY_MODE,
GIMP_NEW_OVERLAY_MODE,
GIMP_SOFTLIGHT_MODE,
GIMP_HARDLIGHT_MODE,
......
......@@ -1050,6 +1050,10 @@ xcf_load_layer_props (XcfInfo *info,
guint32 mode;
info->cp += xcf_read_int32 (info->input, &mode, 1);
if (mode == GIMP_OVERLAY_MODE)
mode = GIMP_SOFTLIGHT_MODE;
gimp_layer_set_mode (*layer, (GimpLayerModeEffects) mode, FALSE);
}
break;
......
......@@ -683,6 +683,9 @@ xcf_save_prop (XcfInfo *info,
mode = va_arg (args, gint32);
size = 4;
if (mode == GIMP_OVERLAY_MODE)
mode = GIMP_SOFTLIGHT_MODE;
xcf_write_prop_type_check_error (info, prop_type);
xcf_write_int32_check_error (info, &size, 1);
xcf_write_int32_check_error (info, (guint32 *) &mode, 1);
......
......@@ -75,7 +75,8 @@ static GimpXcfLoaderFunc * const xcf_loaders[] =
xcf_load_image, /* version 5 */
xcf_load_image, /* version 6 */
xcf_load_image, /* version 7 */
xcf_load_image /* version 8 */
xcf_load_image, /* version 8 */
xcf_load_image /* version 9 */
};
......
......@@ -94,4 +94,5 @@ gimpenums
@GIMP_GRAIN_EXTRACT_MODE:
@GIMP_GRAIN_MERGE_MODE:
@GIMP_COLOR_ERASE_MODE:
@GIMP_NEW_OVERLAY_MODE:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment