From b1d1699f142032571787760991ff0e7e7af7c5cb Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Fri, 21 Mar 2025 13:25:20 +0000 Subject: [PATCH] widgets: Use different color for Histogram borders GimpHistogramView uses the widget's foreground color to draw both the histogram and its border. This causes clipped values to blend into the sides of the border, preventing the user from seeing them. This patch gets the luminance value of the foreground color, then uses that as a threshold to lighten or darken the border color for contrast. --- app/widgets/gimphistogramview.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/widgets/gimphistogramview.c b/app/widgets/gimphistogramview.c index 4ac3bda895..3df2168151 100644 --- a/app/widgets/gimphistogramview.c +++ b/app/widgets/gimphistogramview.c @@ -23,6 +23,7 @@ #include #include "libgimpbase/gimpbase.h" +#include "libgimpcolor/gimpcolor-private.h" #include "libgimpmath/gimpmath.h" #include "widgets-types.h" @@ -306,6 +307,7 @@ gimp_histogram_view_draw (GtkWidget *widget, gdouble max = 0.0; gdouble bg_max = 0.0; gint xstop; + gfloat lum; GdkRGBA grid_color; GdkRGBA color_in; GdkRGBA color_out; @@ -335,6 +337,25 @@ gimp_histogram_view_draw (GtkWidget *widget, &grid_color); gtk_style_context_remove_class (style, "grid"); + /* Alter the border so the histogram stands out against it */ + if (view->histogram) + { + lum = GIMP_RGB_LUMINANCE (grid_color.red, grid_color.green, + grid_color.blue); + if (lum > 0.5) + { + grid_color.red = CLAMP (grid_color.red - 0.33, 0, 1); + grid_color.green = CLAMP (grid_color.green - 0.33, 0, 1); + grid_color.blue = CLAMP (grid_color.blue - 0.33, 0, 1); + } + else + { + grid_color.red = CLAMP (grid_color.red + 0.33, 0, 1); + grid_color.green = CLAMP (grid_color.green + 0.33, 0, 1); + grid_color.blue = CLAMP (grid_color.blue + 0.33, 0, 1); + } + } + gdk_cairo_set_source_rgba (cr, &grid_color); cairo_rectangle (cr, border, border, width - 1, height - 1); cairo_stroke (cr);