From 769e36d7cf5da7a2e7bf3e70eb9deebf10808a52 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 28 Nov 2022 13:50:53 +0000 Subject: [PATCH] core: color pick in image's RGB space Replaces GimpPickableInterface's pixel_to_srgb () functions with pixel_to_rgb(). Now GimpRGB's values should be in the correct image color space from the beginning of the process. --- app/core/gimpimage-color-profile.c | 57 ++++++++++++++++-------------- app/core/gimpimage-color-profile.h | 4 +-- app/core/gimpimage-pick-color.c | 18 ++++++++-- app/core/gimpimage.c | 32 ++++++++--------- app/core/gimpimageproxy.c | 40 ++++++++++----------- app/core/gimplayer.c | 28 +++++++-------- app/core/gimppickable.c | 36 +++++++++---------- app/core/gimppickable.h | 8 ++--- app/core/gimpprojection.c | 28 +++++++-------- app/paint/gimpsmudge.c | 8 ++--- 10 files changed, 138 insertions(+), 121 deletions(-) diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c index a3b067b897..bcf8f2d604 100644 --- a/app/core/gimpimage-color-profile.c +++ b/app/core/gimpimage-color-profile.c @@ -858,25 +858,27 @@ gimp_image_get_color_transform_from_srgb_double (GimpImage *image) } void -gimp_image_color_profile_pixel_to_srgb (GimpImage *image, - const Babl *pixel_format, - gpointer pixel, - GimpRGB *color) +gimp_image_color_profile_pixel_to_rgb (GimpImage *image, + const Babl *pixel_format, + gpointer pixel, + GimpRGB *color) { - GimpColorTransform *transform; + GimpColorProfile *profile = NULL; + const Babl *space = NULL; g_return_if_fail (GIMP_IS_IMAGE (image)); - transform = gimp_image_get_color_transform_to_srgb_double (image); + profile = gimp_image_get_color_profile (image); - if (transform) + if (profile) + space = gimp_color_profile_get_space (profile, + GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC, + NULL); + if (profile) { - gimp_color_transform_process_pixels (transform, - pixel_format, - pixel, - babl_format ("R'G'B'A double"), - color, - 1); + babl_process (babl_fish (pixel_format, + babl_format_with_space ("R'G'B'A double", space)), + pixel, color, 1); } else { @@ -885,25 +887,28 @@ gimp_image_color_profile_pixel_to_srgb (GimpImage *image, } void -gimp_image_color_profile_srgb_to_pixel (GimpImage *image, - const GimpRGB *color, - const Babl *pixel_format, - gpointer pixel) +gimp_image_color_profile_rgb_to_pixel (GimpImage *image, + const GimpRGB *color, + const Babl *pixel_format, + gpointer pixel) { - GimpColorTransform *transform; + GimpColorProfile *profile = NULL; + const Babl *space = NULL; g_return_if_fail (GIMP_IS_IMAGE (image)); - transform = gimp_image_get_color_transform_from_srgb_double (image); + profile = gimp_image_get_color_profile (image); - if (transform) + if (profile) + space = gimp_color_profile_get_space (profile, + GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC, + NULL); + + if (profile) { - gimp_color_transform_process_pixels (transform, - babl_format ("R'G'B'A double"), - color, - pixel_format, - pixel, - 1); + babl_process (babl_fish (babl_format_with_space ("R'G'B'A double", space), + pixel_format), + color, pixel, 1); } else { diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h index 5fd415b598..607b9af531 100644 --- a/app/core/gimpimage-color-profile.h +++ b/app/core/gimpimage-color-profile.h @@ -118,12 +118,12 @@ 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_pixel_to_srgb +void gimp_image_color_profile_pixel_to_rgb (GimpImage *image, const Babl *pixel_format, gpointer pixel, GimpRGB *color); -void gimp_image_color_profile_srgb_to_pixel +void gimp_image_color_profile_rgb_to_pixel (GimpImage *image, const GimpRGB *color, const Babl *pixel_format, diff --git a/app/core/gimpimage-pick-color.c b/app/core/gimpimage-pick-color.c index 90726eb989..8fe2bb2632 100644 --- a/app/core/gimpimage-pick-color.c +++ b/app/core/gimpimage-pick-color.c @@ -17,13 +17,16 @@ #include "config.h" +#include #include #include +#include "libgimpcolor/gimpcolor.h" #include "libgimpmath/gimpmath.h" #include "core-types.h" +#include "gegl/gimp-babl.h" #include "gegl/gimp-gegl-loops.h" #include "gimp.h" @@ -31,6 +34,7 @@ #include "gimpcontainer.h" #include "gimpdrawable.h" #include "gimpimage.h" +#include "gimpimage-color-profile.h" #include "gimpimage-new.h" #include "gimpimage-pick-color.h" #include "gimplayer.h" @@ -145,8 +149,16 @@ gimp_image_pick_color (GimpImage *image, if (show_all && sample_merged) { - const Babl *format = babl_format ("RaGaBaA double"); - gdouble sample[4] = {}; + GimpColorProfile *profile = gimp_image_get_color_profile (image); + const Babl *space = NULL; + gdouble sample[4] = {}; + const Babl *format; + + if (profile) + space = gimp_color_profile_get_space (profile, + GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC, + NULL); + format = babl_format_with_space ("RaGaBaA double", space); if (! result) memset (pixel, 0, babl_format_get_bytes_per_pixel (*sample_format)); @@ -165,7 +177,7 @@ gimp_image_pick_color (GimpImage *image, } if (! result || sample_average) - gimp_pickable_pixel_to_srgb (pickable, format, sample, color); + gimp_pickable_pixel_to_rgb (pickable, format, sample, color); result = TRUE; } diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index f137966cf7..4891734003 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -235,11 +235,11 @@ static void gimp_image_get_pixel_average (GimpPickable *pickable, const GeglRectangle *rect, const Babl *format, gpointer pixel); -static void gimp_image_pixel_to_srgb (GimpPickable *pickable, +static void gimp_image_pixel_to_rgb (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color); -static void gimp_image_srgb_to_pixel (GimpPickable *pickable, +static void gimp_image_rgb_to_pixel (GimpPickable *pickable, const GimpRGB *color, const Babl *format, gpointer pixel); @@ -752,8 +752,8 @@ 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->pixel_to_srgb = gimp_image_pixel_to_srgb; - iface->srgb_to_pixel = gimp_image_srgb_to_pixel; + iface->pixel_to_rgb = gimp_image_pixel_to_rgb; + iface->rgb_to_pixel = gimp_image_rgb_to_pixel; } static void @@ -1687,23 +1687,23 @@ gimp_image_get_pixel_average (GimpPickable *pickable, } static void -gimp_image_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color) +gimp_image_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color) { - gimp_image_color_profile_pixel_to_srgb (GIMP_IMAGE (pickable), - format, pixel, color); + gimp_image_color_profile_pixel_to_rgb (GIMP_IMAGE (pickable), + format, pixel, color); } static void -gimp_image_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel) +gimp_image_rgb_to_pixel (GimpPickable *pickable, + const GimpRGB *color, + const Babl *format, + gpointer pixel) { - gimp_image_color_profile_srgb_to_pixel (GIMP_IMAGE (pickable), - color, format, pixel); + gimp_image_color_profile_rgb_to_pixel (GIMP_IMAGE (pickable), + color, format, pixel); } static GeglRectangle diff --git a/app/core/gimpimageproxy.c b/app/core/gimpimageproxy.c index 21ae77e2ce..e2ffa54fd0 100644 --- a/app/core/gimpimageproxy.c +++ b/app/core/gimpimageproxy.c @@ -117,14 +117,14 @@ static void gimp_image_proxy_get_pixel_average (GimpPickabl const GeglRectangle *rect, const Babl *format, gpointer pixel); -static void gimp_image_proxy_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color); -static void gimp_image_proxy_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel); +static void gimp_image_proxy_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color); +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); @@ -211,8 +211,8 @@ 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->pixel_to_srgb = gimp_image_proxy_pixel_to_srgb; - iface->srgb_to_pixel = gimp_image_proxy_srgb_to_pixel; + iface->pixel_to_rgb = gimp_image_proxy_pixel_to_rgb; + iface->rgb_to_pixel = gimp_image_proxy_rgb_to_pixel; } static void @@ -602,31 +602,31 @@ gimp_image_proxy_get_pixel_average (GimpPickable *pickable, } static void -gimp_image_proxy_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color) +gimp_image_proxy_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color) { GimpImageProxy *image_proxy = GIMP_IMAGE_PROXY (pickable); GimpPickable *proxy_pickable; proxy_pickable = gimp_image_proxy_get_pickable (image_proxy); - gimp_pickable_pixel_to_srgb (proxy_pickable, format, pixel, color); + gimp_pickable_pixel_to_rgb (proxy_pickable, format, pixel, color); } static void -gimp_image_proxy_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel) +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_srgb_to_pixel (proxy_pickable, color, format, pixel); + gimp_pickable_rgb_to_pixel (proxy_pickable, color, format, pixel); } static const guint8 * diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index b2d2bd5a31..e6af2ea70d 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -211,11 +211,11 @@ static GimpColorProfile * static gdouble gimp_layer_get_opacity_at (GimpPickable *pickable, gint x, gint y); -static void gimp_layer_pixel_to_srgb (GimpPickable *pickable, +static void gimp_layer_pixel_to_rgb (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color); -static void gimp_layer_srgb_to_pixel (GimpPickable *pickable, +static void gimp_layer_rgb_to_pixel (GimpPickable *pickable, const GimpRGB *color, const Babl *format, gpointer pixel); @@ -578,8 +578,8 @@ static void gimp_pickable_iface_init (GimpPickableInterface *iface) { iface->get_opacity_at = gimp_layer_get_opacity_at; - iface->pixel_to_srgb = gimp_layer_pixel_to_srgb; - iface->srgb_to_pixel = gimp_layer_srgb_to_pixel; + iface->pixel_to_rgb = gimp_layer_pixel_to_rgb; + iface->rgb_to_pixel = gimp_layer_rgb_to_pixel; } static void @@ -1623,25 +1623,25 @@ gimp_layer_get_opacity_at (GimpPickable *pickable, } static void -gimp_layer_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color) +gimp_layer_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color) { GimpImage *image = gimp_item_get_image (GIMP_ITEM (pickable)); - gimp_pickable_pixel_to_srgb (GIMP_PICKABLE (image), format, pixel, color); + gimp_pickable_pixel_to_rgb (GIMP_PICKABLE (image), format, pixel, color); } static void -gimp_layer_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel) +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_srgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel); + gimp_pickable_rgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel); } static gboolean diff --git a/app/core/gimppickable.c b/app/core/gimppickable.c index af0e2cf0b3..c623b7a03e 100644 --- a/app/core/gimppickable.c +++ b/app/core/gimppickable.c @@ -248,7 +248,7 @@ gimp_pickable_get_color_at (GimpPickable *pickable, if (! gimp_pickable_get_pixel_at (pickable, x, y, NULL, pixel)) return FALSE; - gimp_pickable_pixel_to_srgb (pickable, NULL, pixel, color); + gimp_pickable_pixel_to_rgb (pickable, NULL, pixel, color); return TRUE; } @@ -271,10 +271,10 @@ gimp_pickable_get_opacity_at (GimpPickable *pickable, } void -gimp_pickable_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color) +gimp_pickable_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color) { GimpPickableInterface *pickable_iface; @@ -287,9 +287,9 @@ gimp_pickable_pixel_to_srgb (GimpPickable *pickable, pickable_iface = GIMP_PICKABLE_GET_IFACE (pickable); - if (pickable_iface->pixel_to_srgb) + if (pickable_iface->pixel_to_rgb) { - pickable_iface->pixel_to_srgb (pickable, format, pixel, color); + pickable_iface->pixel_to_rgb (pickable, format, pixel, color); } else { @@ -298,10 +298,10 @@ gimp_pickable_pixel_to_srgb (GimpPickable *pickable, } void -gimp_pickable_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel) +gimp_pickable_rgb_to_pixel (GimpPickable *pickable, + const GimpRGB *color, + const Babl *format, + gpointer pixel) { GimpPickableInterface *pickable_iface; @@ -314,9 +314,9 @@ gimp_pickable_srgb_to_pixel (GimpPickable *pickable, pickable_iface = GIMP_PICKABLE_GET_IFACE (pickable); - if (pickable_iface->srgb_to_pixel) + if (pickable_iface->rgb_to_pixel) { - pickable_iface->srgb_to_pixel (pickable, color, format, pixel); + pickable_iface->rgb_to_pixel (pickable, color, format, pixel); } else { @@ -333,10 +333,10 @@ gimp_pickable_srgb_to_image_color (GimpPickable *pickable, g_return_if_fail (color != NULL); g_return_if_fail (image_color != NULL); - gimp_pickable_srgb_to_pixel (pickable, - color, - babl_format ("R'G'B'A double"), - image_color); + gimp_pickable_rgb_to_pixel (pickable, + color, + babl_format ("R'G'B'A double"), + image_color); } gboolean @@ -377,7 +377,7 @@ gimp_pickable_pick_color (GimpPickable *pickable, format, sample); } - gimp_pickable_pixel_to_srgb (pickable, format, sample, color); + gimp_pickable_pixel_to_rgb (pickable, format, sample, color); return TRUE; } diff --git a/app/core/gimppickable.h b/app/core/gimppickable.h index e422abebff..3014fd8cba 100644 --- a/app/core/gimppickable.h +++ b/app/core/gimppickable.h @@ -47,11 +47,11 @@ struct _GimpPickableInterface const GeglRectangle *rect, const Babl *format, gpointer pixel); - void (* pixel_to_srgb) (GimpPickable *pickable, + void (* pixel_to_rgb) (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color); - void (* srgb_to_pixel) (GimpPickable *pickable, + void (* rgb_to_pixel) (GimpPickable *pickable, const GimpRGB *color, const Babl *format, gpointer pixel); @@ -79,11 +79,11 @@ void gimp_pickable_get_pixel_average (GimpPickable *pickab const GeglRectangle *rect, const Babl *format, gpointer pixel); -void gimp_pickable_pixel_to_srgb (GimpPickable *pickable, +void gimp_pickable_pixel_to_rgb (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color); -void gimp_pickable_srgb_to_pixel (GimpPickable *pickable, +void gimp_pickable_rgb_to_pixel (GimpPickable *pickable, const GimpRGB *color, const Babl *format, gpointer pixel); diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c index 848d85c0c3..df33cb5144 100644 --- a/app/core/gimpprojection.c +++ b/app/core/gimpprojection.c @@ -116,11 +116,11 @@ static void gimp_projection_get_pixel_average (GimpPickable *picka const GeglRectangle *rect, const Babl *format, gpointer pixel); -static void gimp_projection_pixel_to_srgb (GimpPickable *pickable, +static void gimp_projection_pixel_to_rgb (GimpPickable *pickable, const Babl *format, gpointer pixel, GimpRGB *color); -static void gimp_projection_srgb_to_pixel (GimpPickable *pickable, +static void gimp_projection_rgb_to_pixel (GimpPickable *pickable, const GimpRGB *color, const Babl *format, gpointer pixel); @@ -222,8 +222,8 @@ 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->pixel_to_srgb = gimp_projection_pixel_to_srgb; - iface->srgb_to_pixel = gimp_projection_srgb_to_pixel; + iface->pixel_to_rgb = gimp_projection_pixel_to_rgb; + iface->rgb_to_pixel = gimp_projection_rgb_to_pixel; } static void @@ -435,27 +435,27 @@ gimp_projection_get_pixel_average (GimpPickable *pickable, } static void -gimp_projection_pixel_to_srgb (GimpPickable *pickable, - const Babl *format, - gpointer pixel, - GimpRGB *color) +gimp_projection_pixel_to_rgb (GimpPickable *pickable, + const Babl *format, + gpointer pixel, + GimpRGB *color) { GimpProjection *proj = GIMP_PROJECTION (pickable); GimpImage *image = gimp_projectable_get_image (proj->priv->projectable); - gimp_pickable_pixel_to_srgb (GIMP_PICKABLE (image), format, pixel, color); + gimp_pickable_pixel_to_rgb (GIMP_PICKABLE (image), format, pixel, color); } static void -gimp_projection_srgb_to_pixel (GimpPickable *pickable, - const GimpRGB *color, - const Babl *format, - gpointer pixel) +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_srgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel); + gimp_pickable_rgb_to_pixel (GIMP_PICKABLE (image), color, format, pixel); } diff --git a/app/paint/gimpsmudge.c b/app/paint/gimpsmudge.c index 9e74435c69..f1759bdbc4 100644 --- a/app/paint/gimpsmudge.c +++ b/app/paint/gimpsmudge.c @@ -455,10 +455,10 @@ gimp_smudge_motion (GimpPaintCore *paint_core, /* Convert to linear RGBA */ if (brush_color_ptr) - gimp_pickable_srgb_to_pixel (dest_pickable, - &brush_color, - babl_format ("RGBA double"), - &brush_color); + gimp_pickable_rgb_to_pixel (dest_pickable, + &brush_color, + babl_format ("RGBA double"), + &brush_color); n_strokes = gimp_symmetry_get_size (sym); for (i = 0; i < n_strokes; i++)