From 643a31535b44c369edc8c5d601b1b14a3db2f207 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Thu, 10 Apr 2025 13:05:20 +0200 Subject: Clamp color channel values before converting to hex This is needed as `GdkRGBA` may return out of range values when doing colorspace conversion. See https://gitlab.gnome.org/GNOME/gtk/-/issues/7488 --- main/src/ui/util/helper.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'main/src/ui/util') diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 60e0e81c..1e3b4c7e 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -90,10 +90,10 @@ public static Gdk.RGBA get_label_pango_color(Label label, string css_color) { public static string rgba_to_hex(Gdk.RGBA rgba) { return "#%02x%02x%02x%02x".printf( - (uint)(Math.round(rgba.red*255)), - (uint)(Math.round(rgba.green*255)), - (uint)(Math.round(rgba.blue*255)), - (uint)(Math.round(rgba.alpha*255))) + (uint8)(Math.round(rgba.red.clamp(0,1)*255)), + (uint8)(Math.round(rgba.green.clamp(0,1)*255)), + (uint8)(Math.round(rgba.blue.clamp(0,1)*255)), + (uint8)(Math.round(rgba.alpha.clamp(0,1)*255))) .up(); } -- cgit v1.3