app: get rid of rgb_to_pixel() GimpPickable method and related functions.

We don't try anymore to convert early from a pickable color to another
format/space. Now we are able to get a GeglColor and move it around,
doing only last-second (when needed) conversions.
This commit is contained in:
Jehan 2023-12-22 15:47:36 +09:00
parent d55325829f
commit 46121685b8
14 changed files with 18 additions and 199 deletions

View File

@ -567,7 +567,7 @@ gimp_channel_convert (GimpItem *item,
{
GeglBuffer *new_buffer;
const Babl *format;
GimpRGB background;
GeglColor *background = gegl_color_new ("transparent");
format = gimp_drawable_get_format_without_alpha (drawable);
@ -577,11 +577,9 @@ gimp_channel_convert (GimpItem *item,
gimp_item_get_height (item)),
format);
gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
gimp_gegl_apply_flatten (gimp_drawable_get_buffer (drawable),
NULL, NULL,
new_buffer, &background, NULL,
new_buffer, background,
GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
gimp_drawable_set_buffer_full (drawable, FALSE, NULL,
@ -592,6 +590,7 @@ gimp_channel_convert (GimpItem *item,
0, 0),
TRUE);
g_object_unref (new_buffer);
g_object_unref (background);
}
if (G_TYPE_FROM_INSTANCE (channel) == GIMP_TYPE_CHANNEL)

View File

@ -844,36 +844,6 @@ gimp_image_get_color_transform_from_srgb_double (GimpImage *image)
return private->transform_from_srgb_double;
}
void
gimp_image_color_profile_rgb_to_pixel (GimpImage *image,
const GimpRGB *color,
const Babl *pixel_format,
gpointer pixel)
{
GimpColorProfile *profile = NULL;
const Babl *space = NULL;
g_return_if_fail (GIMP_IS_IMAGE (image));
profile = gimp_image_get_color_profile (image);
if (profile)
space = gimp_color_profile_get_space (profile,
GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
NULL);
if (profile)
{
babl_process (babl_fish (babl_format_with_space ("R'G'B'A double", space),
pixel_format),
color, pixel, 1);
}
else
{
gimp_rgba_get_pixel (color, pixel_format, pixel);
}
}
/* internal API */

View File

@ -116,12 +116,6 @@ GimpColorTransform * gimp_image_get_color_transform_to_srgb_double
GimpColorTransform * gimp_image_get_color_transform_from_srgb_double
(GimpImage *image);
void gimp_image_color_profile_rgb_to_pixel
(GimpImage *image,
const GimpRGB *color,
const Babl *pixel_format,
gpointer pixel);
/* internal API, to be called only from gimpimage.c */

View File

@ -673,9 +673,6 @@ gimp_image_merge_layers (GimpImage *image,
(gimp_drawable_is_indexed (GIMP_DRAWABLE (layer)) &&
! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer))))
{
GeglColor *color;
GimpRGB bg;
merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1),
gimp_image_get_layer_format (image, FALSE),
gimp_object_get_name (bottom_layer),
@ -690,14 +687,8 @@ gimp_image_merge_layers (GimpImage *image,
}
/* get the background for compositing */
color = gimp_context_get_background (context);
gegl_color_get_rgba_with_space (color, &bg.r, &bg.g, &bg.b, &bg.a, NULL);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer),
&bg, &bg);
flatten_node = gimp_gegl_create_flatten_node
(&bg,
gimp_drawable_get_space (GIMP_DRAWABLE (layer)),
(gimp_context_get_background (context),
gimp_layer_get_real_composite_space (bottom_layer));
}
else

View File

@ -236,10 +236,6 @@ static void gimp_image_get_pixel_average (GimpPickable *pickable,
const GeglRectangle *rect,
const Babl *format,
gpointer pixel);
static void gimp_image_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
static void gimp_image_projection_buffer_notify
(GimpProjection *projection,
@ -734,7 +730,6 @@ gimp_pickable_iface_init (GimpPickableInterface *iface)
iface->get_pixel_at = gimp_image_get_pixel_at;
iface->get_opacity_at = gimp_image_get_opacity_at;
iface->get_pixel_average = gimp_image_get_pixel_average;
iface->rgb_to_pixel = gimp_image_rgb_to_pixel;
}
static void
@ -1671,16 +1666,6 @@ gimp_image_get_pixel_average (GimpPickable *pickable,
pixel);
}
static void
gimp_image_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel)
{
gimp_image_color_profile_rgb_to_pixel (GIMP_IMAGE (pickable),
color, format, pixel);
}
static GeglRectangle
gimp_image_get_bounding_box (GimpProjectable *projectable)
{

View File

@ -117,10 +117,6 @@ static void gimp_image_proxy_get_pixel_average (GimpPickabl
const GeglRectangle *rect,
const Babl *format,
gpointer pixel);
static void gimp_image_proxy_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
static const guint8 * gimp_image_proxy_get_icc_profile (GimpColorManaged *managed,
gsize *len);
@ -207,7 +203,6 @@ gimp_image_proxy_pickable_iface_init (GimpPickableInterface *iface)
iface->get_pixel_at = gimp_image_proxy_get_pixel_at;
iface->get_opacity_at = gimp_image_proxy_get_opacity_at;
iface->get_pixel_average = gimp_image_proxy_get_pixel_average;
iface->rgb_to_pixel = gimp_image_proxy_rgb_to_pixel;
}
static void
@ -596,20 +591,6 @@ gimp_image_proxy_get_pixel_average (GimpPickable *pickable,
gimp_pickable_get_pixel_average (proxy_pickable, rect, format, pixel);
}
static void
gimp_image_proxy_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel)
{
GimpImageProxy *image_proxy = GIMP_IMAGE_PROXY (pickable);
GimpPickable *proxy_pickable;
proxy_pickable = gimp_image_proxy_get_pickable (image_proxy);
gimp_pickable_rgb_to_pixel (proxy_pickable, color, format, pixel);
}
static const guint8 *
gimp_image_proxy_get_icc_profile (GimpColorManaged *managed,
gsize *len)

View File

@ -211,10 +211,6 @@ static GimpColorProfile *
static gdouble gimp_layer_get_opacity_at (GimpPickable *pickable,
gint x,
gint y);
static void gimp_layer_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
static gboolean gimp_layer_real_is_alpha_locked (GimpLayer *layer,
GimpLayer **locked_layer);
@ -574,7 +570,6 @@ static void
gimp_pickable_iface_init (GimpPickableInterface *iface)
{
iface->get_opacity_at = gimp_layer_get_opacity_at;
iface->rgb_to_pixel = gimp_layer_rgb_to_pixel;
}
static void
@ -1616,17 +1611,6 @@ gimp_layer_get_opacity_at (GimpPickable *pickable,
return value;
}
static void
gimp_layer_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel)
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (pickable));
gimp_pickable_rgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel);
}
static gboolean
gimp_layer_real_is_alpha_locked (GimpLayer *layer,
GimpLayer **locked_layer)
@ -2163,13 +2147,13 @@ gimp_layer_create_mask (GimpLayer *layer,
if (gimp_drawable_has_alpha (drawable))
{
GimpRGB background;
gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
GeglColor *background = gegl_color_new ("transparent");
gimp_gegl_apply_flatten (src_buffer, NULL, NULL,
dest_buffer, &background, NULL,
dest_buffer, background,
GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
g_object_unref (background);
}
else
{
@ -2501,8 +2485,6 @@ gimp_layer_remove_alpha (GimpLayer *layer,
GimpContext *context)
{
GeglBuffer *new_buffer;
GeglColor *color;
GimpRGB background;
g_return_if_fail (GIMP_IS_LAYER (layer));
g_return_if_fail (GIMP_IS_CONTEXT (context));
@ -2516,15 +2498,9 @@ gimp_layer_remove_alpha (GimpLayer *layer,
gimp_item_get_height (GIMP_ITEM (layer))),
gimp_drawable_get_format_without_alpha (GIMP_DRAWABLE (layer)));
color = gimp_context_get_background (context);
gegl_color_get_rgba_with_space (color, &background.r, &background.g, &background.b, &background.a, NULL);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (layer),
&background, &background);
gimp_gegl_apply_flatten (gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)),
NULL, NULL,
new_buffer, &background,
gimp_drawable_get_space (GIMP_DRAWABLE (layer)),
NULL, NULL, new_buffer,
gimp_context_get_background (context),
gimp_layer_get_real_composite_space (layer));
gimp_drawable_set_buffer (GIMP_DRAWABLE (layer),

View File

@ -287,48 +287,6 @@ gimp_pickable_get_opacity_at (GimpPickable *pickable,
return GIMP_OPACITY_TRANSPARENT;
}
void
gimp_pickable_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel)
{
GimpPickableInterface *pickable_iface;
g_return_if_fail (GIMP_IS_PICKABLE (pickable));
g_return_if_fail (color != NULL);
g_return_if_fail (pixel != NULL);
if (! format)
format = gimp_pickable_get_format (pickable);
pickable_iface = GIMP_PICKABLE_GET_IFACE (pickable);
if (pickable_iface->rgb_to_pixel)
{
pickable_iface->rgb_to_pixel (pickable, color, format, pixel);
}
else
{
gimp_rgba_get_pixel (color, format, pixel);
}
}
void
gimp_pickable_srgb_to_image_color (GimpPickable *pickable,
const GimpRGB *color,
GimpRGB *image_color)
{
g_return_if_fail (GIMP_IS_PICKABLE (pickable));
g_return_if_fail (color != NULL);
g_return_if_fail (image_color != NULL);
gimp_pickable_rgb_to_pixel (pickable,
color,
babl_format ("R'G'B'A double"),
image_color);
}
gboolean
gimp_pickable_pick_color (GimpPickable *pickable,
gint x,

View File

@ -48,10 +48,6 @@ struct _GimpPickableInterface
const GeglRectangle *rect,
const Babl *format,
gpointer pixel);
void (* rgb_to_pixel) (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
};
@ -76,13 +72,6 @@ void gimp_pickable_get_pixel_average (GimpPickable *pick
const GeglRectangle *rect,
const Babl *format,
gpointer pixel);
void gimp_pickable_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
void gimp_pickable_srgb_to_image_color (GimpPickable *pickable,
const GimpRGB *color,
GimpRGB *image_color);
gboolean gimp_pickable_pick_color (GimpPickable *pickable,
gint x,

View File

@ -116,10 +116,6 @@ static void gimp_projection_get_pixel_average (GimpPickable *picka
const GeglRectangle *rect,
const Babl *format,
gpointer pixel);
static void gimp_projection_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel);
static void gimp_projection_allocate_buffer (GimpProjection *proj);
static void gimp_projection_free_buffer (GimpProjection *proj);
@ -218,7 +214,6 @@ gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
iface->get_pixel_at = gimp_projection_get_pixel_at;
iface->get_opacity_at = gimp_projection_get_opacity_at;
iface->get_pixel_average = gimp_projection_get_pixel_average;
iface->rgb_to_pixel = gimp_projection_rgb_to_pixel;
}
static void
@ -429,18 +424,6 @@ gimp_projection_get_pixel_average (GimpPickable *pickable,
pixel);
}
static void
gimp_projection_rgb_to_pixel (GimpPickable *pickable,
const GimpRGB *color,
const Babl *format,
gpointer pixel)
{
GimpProjection *proj = GIMP_PROJECTION (pickable);
GimpImage *image = gimp_projectable_get_image (proj->priv->projectable);
gimp_pickable_rgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel);
}
/* public functions */

View File

@ -405,8 +405,7 @@ gimp_gegl_apply_flatten (GeglBuffer *src_buffer,
GimpProgress *progress,
const gchar *undo_desc,
GeglBuffer *dest_buffer,
const GimpRGB *background,
const Babl *space,
GeglColor *background,
GimpLayerColorSpace composite_space)
{
GeglNode *node;
@ -414,9 +413,9 @@ gimp_gegl_apply_flatten (GeglBuffer *src_buffer,
g_return_if_fail (GEGL_IS_BUFFER (src_buffer));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
g_return_if_fail (background != NULL);
g_return_if_fail (GEGL_IS_COLOR (background));
node = gimp_gegl_create_flatten_node (background, space, composite_space);
node = gimp_gegl_create_flatten_node (background, composite_space);
gimp_gegl_apply_operation (src_buffer, progress, undo_desc,
node, dest_buffer, NULL, FALSE);

View File

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

View File

@ -31,8 +31,7 @@
GeglNode *
gimp_gegl_create_flatten_node (const GimpRGB *background,
const Babl *space,
gimp_gegl_create_flatten_node (GeglColor *background,
GimpLayerColorSpace composite_space)
{
GeglNode *node;
@ -40,9 +39,8 @@ gimp_gegl_create_flatten_node (const GimpRGB *background,
GeglNode *output;
GeglNode *color;
GeglNode *mode;
GeglColor *c;
g_return_val_if_fail (background != NULL, NULL);
g_return_val_if_fail (GEGL_IS_COLOR (background), NULL);
g_return_val_if_fail (composite_space == GIMP_LAYER_COLOR_SPACE_RGB_LINEAR ||
composite_space == GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL,
NULL);
@ -52,10 +50,9 @@ 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, space);
color = gegl_node_new_child (node,
"operation", "gegl:color",
"value", c,
"value", background,
"format", gimp_layer_mode_get_format (
GIMP_LAYER_MODE_NORMAL,
GIMP_LAYER_COLOR_SPACE_AUTO,
@ -63,7 +60,6 @@ gimp_gegl_create_flatten_node (const GimpRGB *background,
GIMP_LAYER_COMPOSITE_AUTO,
NULL),
NULL);
g_object_unref (c);
gimp_gegl_node_set_underlying_operation (node, color);

View File

@ -22,8 +22,7 @@
#define __GIMP_GEGL_NODES_H__
GeglNode * gimp_gegl_create_flatten_node (const GimpRGB *background,
const Babl *space,
GeglNode * gimp_gegl_create_flatten_node (GeglColor *background,
GimpLayerColorSpace composite_space);
GeglNode * gimp_gegl_create_apply_opacity_node (GeglBuffer *mask,
gint mask_offset_x,