Issue #1997 - Colors not properly converted to image's color space

Add a Babl space parameter to gimp_gegl_color_new() and all utility
functions using it. Pass NULL if the GimpRGB actually is sRGB, pass
the image's layer space if the color was already converted using
gimp_pickable_srgb_to_image_color() or similar.
This commit is contained in:
Michael Natterer 2018-08-09 20:04:44 +02:00
parent 753523c4d1
commit 6938d11716
18 changed files with 71 additions and 55 deletions

View file

@ -419,7 +419,7 @@ gimp_channel_get_node (GimpFilter *filter)
"format", color_format,
NULL);
gimp_gegl_node_set_color (channel->color_node,
&channel->color);
&channel->color, NULL);
g_warn_if_fail (channel->mask_node == NULL);
@ -608,7 +608,7 @@ gimp_channel_convert (GimpItem *item,
gimp_gegl_apply_flatten (gimp_drawable_get_buffer (drawable),
NULL, NULL,
new_buffer, &background,
new_buffer, &background, NULL,
GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
@ -1713,7 +1713,7 @@ gimp_channel_set_color (GimpChannel *channel,
if (gimp_filter_peek_node (GIMP_FILTER (channel)))
{
gimp_gegl_node_set_color (channel->color_node,
&channel->color);
&channel->color, NULL);
}
gimp_drawable_update (GIMP_DRAWABLE (channel), 0, 0, -1, -1);
@ -1764,7 +1764,7 @@ gimp_channel_set_opacity (GimpChannel *channel,
if (gimp_filter_peek_node (GIMP_FILTER (channel)))
{
gimp_gegl_node_set_color (channel->color_node,
&channel->color);
&channel->color, NULL);
}
gimp_drawable_update (GIMP_DRAWABLE (channel), 0, 0, -1, -1);

View file

@ -132,7 +132,8 @@ gimp_drawable_fill_buffer (GimpDrawable *drawable,
if (! gimp_drawable_has_alpha (drawable))
gimp_rgb_set_alpha (&image_color, 1.0);
gegl_color = gimp_gegl_color_new (&image_color);
gegl_color = gimp_gegl_color_new (&image_color,
gimp_drawable_get_space (drawable));
gegl_buffer_set_color (buffer, NULL, gegl_color);
g_object_unref (gegl_color);
}

View file

@ -102,7 +102,7 @@ gimp_drawable_offset (GimpDrawable *drawable,
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&bg, &bg);
color = gimp_gegl_color_new (&bg);
color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable));
gegl_buffer_set_color (new_buffer, NULL, color);
g_object_unref (color);
}

View file

@ -235,7 +235,7 @@ gimp_drawable_transform_buffer_flip (GimpDrawable *drawable,
&bg, &bg);
}
color = gimp_gegl_color_new (&bg);
color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable));
gegl_buffer_set_color (new_buffer, NULL, color);
g_object_unref (color);
@ -500,7 +500,7 @@ gimp_drawable_transform_buffer_rotate (GimpDrawable *drawable,
&bg, &bg);
}
color = gimp_gegl_color_new (&bg);
color = gimp_gegl_color_new (&bg, gimp_drawable_get_space (drawable));
gegl_buffer_set_color (new_buffer, NULL, color);
g_object_unref (color);

View file

@ -589,8 +589,10 @@ gimp_image_merge_layers (GimpImage *image,
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer),
&bg, &bg);
flatten_node = gimp_gegl_create_flatten_node (
&bg, gimp_layer_get_real_composite_space (bottom_layer));
flatten_node = gimp_gegl_create_flatten_node
(&bg,
gimp_drawable_get_space (GIMP_DRAWABLE (layer)),
gimp_layer_get_real_composite_space (bottom_layer));
position = 0;
}

View file

@ -2110,7 +2110,7 @@ gimp_layer_create_mask (GimpLayer *layer,
gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
gimp_gegl_apply_flatten (src_buffer, NULL, NULL,
dest_buffer, &background,
dest_buffer, &background, NULL,
GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
}
else
@ -2449,6 +2449,7 @@ gimp_layer_remove_alpha (GimpLayer *layer,
gimp_gegl_apply_flatten (gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)),
NULL, NULL,
new_buffer, &background,
gimp_drawable_get_space (GIMP_DRAWABLE (layer)),
gimp_layer_get_real_composite_space (layer));
gimp_drawable_set_buffer (GIMP_DRAWABLE (layer),

View file

@ -349,6 +349,7 @@ gimp_gegl_apply_flatten (GeglBuffer *src_buffer,
const gchar *undo_desc,
GeglBuffer *dest_buffer,
const GimpRGB *background,
const Babl *space,
GimpLayerColorSpace composite_space)
{
GeglNode *node;
@ -358,7 +359,7 @@ gimp_gegl_apply_flatten (GeglBuffer *src_buffer,
g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
g_return_if_fail (background != NULL);
node = gimp_gegl_create_flatten_node (background, composite_space);
node = gimp_gegl_create_flatten_node (background, space, composite_space);
gimp_gegl_apply_operation (src_buffer, progress, undo_desc,
node, dest_buffer, NULL, FALSE);

View file

@ -61,6 +61,7 @@ void gimp_gegl_apply_flatten (GeglBuffer *src_buffer,
const gchar *undo_desc,
GeglBuffer *dest_buffer,
const GimpRGB *background,
const Babl *space,
GimpLayerColorSpace composite_space);
void gimp_gegl_apply_feather (GeglBuffer *src_buffer,

View file

@ -32,6 +32,7 @@
GeglNode *
gimp_gegl_create_flatten_node (const GimpRGB *background,
const Babl *space,
GimpLayerColorSpace composite_space)
{
GeglNode *node;
@ -51,7 +52,7 @@ gimp_gegl_create_flatten_node (const GimpRGB *background,
input = gegl_node_get_input_proxy (node, "input");
output = gegl_node_get_output_proxy (node, "output");
c = gimp_gegl_color_new (background);
c = gimp_gegl_color_new (background, space);
color = gegl_node_new_child (node,
"operation", "gegl:color",
"value", c,
@ -217,14 +218,15 @@ gimp_gegl_node_set_matrix (GeglNode *node,
void
gimp_gegl_node_set_color (GeglNode *node,
const GimpRGB *color)
const GimpRGB *color,
const Babl *space)
{
GeglColor *gegl_color;
g_return_if_fail (GEGL_IS_NODE (node));
g_return_if_fail (color != NULL);
gegl_color = gimp_gegl_color_new (color);
gegl_color = gimp_gegl_color_new (color, space);
gegl_node_set (node,
"value", gegl_color,

View file

@ -23,6 +23,7 @@
GeglNode * gimp_gegl_create_flatten_node (const GimpRGB *background,
const Babl *space,
GimpLayerColorSpace composite_space);
GeglNode * gimp_gegl_create_apply_opacity_node (GeglBuffer *mask,
gint mask_offset_x,
@ -44,7 +45,8 @@ void gimp_gegl_mode_node_set_opacity (GeglNode *node,
void gimp_gegl_node_set_matrix (GeglNode *node,
const GimpMatrix3 *matrix);
void gimp_gegl_node_set_color (GeglNode *node,
const GimpRGB *color);
const GimpRGB *color,
const Babl *space);
#endif /* __GIMP_GEGL_NODES_H__ */

View file

@ -61,14 +61,17 @@ gimp_gegl_get_op_enum_type (const gchar *operation,
}
GeglColor *
gimp_gegl_color_new (const GimpRGB *rgb)
gimp_gegl_color_new (const GimpRGB *rgb,
const Babl *space)
{
GeglColor *color;
g_return_val_if_fail (rgb != NULL, NULL);
color = gegl_color_new (NULL);
gegl_color_set_pixel (color, babl_format ("R'G'B'A double"), rgb);
gegl_color_set_pixel (color,
babl_format_with_space ("R'G'B'A double", space),
rgb);
return color;
}

View file

@ -25,7 +25,8 @@
GType gimp_gegl_get_op_enum_type (const gchar *operation,
const gchar *property);
GeglColor * gimp_gegl_color_new (const GimpRGB *rgb);
GeglColor * gimp_gegl_color_new (const GimpRGB *rgb,
const Babl *space);
void gimp_gegl_progress_connect (GeglNode *node,
GimpProgress *progress,

View file

@ -540,7 +540,7 @@ gimp_operation_config_sync_node (GObject *config,
gimp_value_get_rgb (&value, &gimp_color);
g_value_unset (&value);
gegl_color = gimp_gegl_color_new (&gimp_color);
gegl_color = gimp_gegl_color_new (&gimp_color, NULL);
g_value_init (&value, gegl_pspec->value_type);
g_value_take_object (&value, gegl_color);
@ -699,7 +699,7 @@ gimp_operation_config_config_notify (GObject *config,
gimp_value_get_rgb (&value, &gimp_color);
g_value_unset (&value);
gegl_color = gimp_gegl_color_new (&gimp_color);
gegl_color = gimp_gegl_color_new (&gimp_color, NULL);
g_value_init (&value, gegl_pspec->value_type);
g_value_take_object (&value, gegl_color);

View file

@ -157,7 +157,7 @@ gimp_eraser_motion (GimpPaintCore *paint_core,
gimp_context_get_background (context, &background);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&background, &background);
color = gimp_gegl_color_new (&background);
color = gimp_gegl_color_new (&background, gimp_drawable_get_space (drawable));
if (options->anti_erase)
paint_mode = GIMP_LAYER_MODE_ANTI_ERASE;

View file

@ -392,7 +392,7 @@ gimp_ink_motion (GimpPaintCore *paint_core,
gimp_context_get_foreground (context, &foreground);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&foreground, &foreground);
color = gimp_gegl_color_new (&foreground);
color = gimp_gegl_color_new (&foreground, gimp_drawable_get_space (drawable));
for (i = 0; i < n_strokes; i++)
{

View file

@ -217,7 +217,8 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
opacity *= gradient_color.a;
gimp_rgb_set_alpha (&gradient_color, GIMP_OPACITY_OPAQUE);
color = gimp_gegl_color_new (&gradient_color);
color = gimp_gegl_color_new (&gradient_color,
NULL /* EEK SPACE? */);
gegl_buffer_set_color (paint_buffer, NULL, color);
g_object_unref (color);
@ -248,7 +249,8 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
gimp_context_get_foreground (context, &foreground);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&foreground, &foreground);
color = gimp_gegl_color_new (&foreground);
color = gimp_gegl_color_new (&foreground,
gimp_drawable_get_space (drawable));
gegl_buffer_set_color (paint_buffer, NULL, color);
g_object_unref (color);

View file

@ -535,7 +535,7 @@ plug_in_applylens_invoker (GimpProcedure *procedure,
else
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:apply-lens",
@ -972,7 +972,7 @@ plug_in_colortoalpha_invoker (GimpProcedure *procedure,
{
/* XXX: fixme disable for gray, and add alpha when needed */
GeglColor *gegl_color = gimp_gegl_color_new (&color);
GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL);
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gegl:color-to-alpha",
@ -1158,7 +1158,7 @@ plug_in_cubism_invoker (GimpProcedure *procedure,
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:cubism",
@ -1553,8 +1553,8 @@ plug_in_exchange_invoker (GimpProcedure *procedure,
gimp_rgb_set_uchar (&from, from_red, from_green, from_blue);
gimp_rgb_set_uchar (&to, to_red, to_green, to_blue);
gegl_from = gimp_gegl_color_new (&from);
gegl_to = gimp_gegl_color_new (&to);
gegl_from = gimp_gegl_color_new (&from, NULL);
gegl_to = gimp_gegl_color_new (&to, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:color-exchange",
@ -1992,7 +1992,7 @@ plug_in_lens_distortion_invoker (GimpProcedure *procedure,
gimp_rgb_set_alpha (&color, 1.0);
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:lens-distortion",
@ -2097,10 +2097,10 @@ plug_in_maze_invoker (GimpProcedure *procedure,
GimpRGB color;
gimp_context_get_foreground (context, &color);
fg_color = gimp_gegl_color_new (&color);
fg_color = gimp_gegl_color_new (&color, NULL);
gimp_context_get_background (context, &color);
bg_color = gimp_gegl_color_new (&color);
bg_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:maze",
@ -2352,10 +2352,10 @@ plug_in_mosaic_invoker (GimpProcedure *procedure,
GimpRGB fgcolor, bgcolor;
gimp_context_get_background (context, &bgcolor);
bg_color = gimp_gegl_color_new (&bgcolor);
bg_color = gimp_gegl_color_new (&bgcolor, NULL);
gimp_context_get_foreground (context, &fgcolor);
fg_color = gimp_gegl_color_new (&fgcolor);
fg_color = gimp_gegl_color_new (&fgcolor, NULL);
}
else
{
@ -2429,7 +2429,7 @@ plug_in_nova_invoker (GimpProcedure *procedure,
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GeglNode *node;
GeglColor *gegl_color = gimp_gegl_color_new (&color);
GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL);
gdouble center_x = (gdouble) xcenter / (gdouble) gimp_item_get_width (GIMP_ITEM (drawable));
gdouble center_y = (gdouble) ycenter / (gdouble) gimp_item_get_height (GIMP_ITEM (drawable));
@ -2520,7 +2520,7 @@ plug_in_papertile_invoker (GimpProcedure *procedure,
break;
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:tile-paper",
@ -3404,8 +3404,8 @@ plug_in_sinus_invoker (GimpProcedure *procedure,
gimp_rgb_set_alpha (&col1, alpha1);
gimp_rgb_set_alpha (&col2, alpha2);
gegl_color1 = gimp_gegl_color_new (&col1);
gegl_color2 = gimp_gegl_color_new (&col2);
gegl_color1 = gimp_gegl_color_new (&col1, NULL);
gegl_color2 = gimp_gegl_color_new (&col2, NULL);
gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height);
@ -3827,7 +3827,7 @@ plug_in_vpropagate_invoker (GimpProcedure *procedure,
else
gimp_context_get_background (context, &color);
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
break;
case 6:

View file

@ -224,7 +224,7 @@ HELP
else
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:apply-lens",
@ -724,7 +724,7 @@ HELP
{
/* XXX: fixme disable for gray, and add alpha when needed */
GeglColor *gegl_color = gimp_gegl_color_new (&color);
GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL);
GeglNode *node =
gegl_node_new_child (NULL,
"operation", "gegl:color-to-alpha",
@ -922,7 +922,7 @@ HELP
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:cubism",
@ -1370,8 +1370,8 @@ HELP
gimp_rgb_set_uchar (&from, from_red, from_green, from_blue);
gimp_rgb_set_uchar (&to, to_red, to_green, to_blue);
gegl_from = gimp_gegl_color_new (&from);
gegl_to = gimp_gegl_color_new (&to);
gegl_from = gimp_gegl_color_new (&from, NULL);
gegl_to = gimp_gegl_color_new (&to, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:color-exchange",
@ -1901,7 +1901,7 @@ HELP
gimp_rgb_set_alpha (&color, 1.0);
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:lens-distortion",
@ -2023,10 +2023,10 @@ HELP
GimpRGB color;
gimp_context_get_foreground (context, &color);
fg_color = gimp_gegl_color_new (&color);
fg_color = gimp_gegl_color_new (&color, NULL);
gimp_context_get_background (context, &color);
bg_color = gimp_gegl_color_new (&color);
bg_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:maze",
@ -2301,10 +2301,10 @@ HELP
GimpRGB fgcolor, bgcolor;
gimp_context_get_background (context, &bgcolor);
bg_color = gimp_gegl_color_new (&bgcolor);
bg_color = gimp_gegl_color_new (&bgcolor, NULL);
gimp_context_get_foreground (context, &fgcolor);
fg_color = gimp_gegl_color_new (&fgcolor);
fg_color = gimp_gegl_color_new (&fgcolor, NULL);
}
else
{
@ -2386,7 +2386,7 @@ HELP
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GeglNode *node;
GeglColor *gegl_color = gimp_gegl_color_new (&color);
GeglColor *gegl_color = gimp_gegl_color_new (&color, NULL);
gdouble center_x = (gdouble) xcenter / (gdouble) gimp_item_get_width (GIMP_ITEM (drawable));
gdouble center_y = (gdouble) ycenter / (gdouble) gimp_item_get_height (GIMP_ITEM (drawable));
@ -2485,7 +2485,7 @@ HELP
break;
}
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
node = gegl_node_new_child (NULL,
"operation", "gegl:tile-paper",
@ -3486,8 +3486,8 @@ sub plug_in_sinus {
gimp_rgb_set_alpha (&col1, alpha1);
gimp_rgb_set_alpha (&col2, alpha2);
gegl_color1 = gimp_gegl_color_new (&col1);
gegl_color2 = gimp_gegl_color_new (&col2);
gegl_color1 = gimp_gegl_color_new (&col1, NULL);
gegl_color2 = gimp_gegl_color_new (&col2, NULL);
gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height);
@ -3973,7 +3973,7 @@ HELP
else
gimp_context_get_background (context, &color);
gegl_color = gimp_gegl_color_new (&color);
gegl_color = gimp_gegl_color_new (&color, NULL);
break;
case 6: