[gimp] Bug 779942 - Make GimpPickButton honor monitor profile



commit 064c4527cb53e473f0582dc6f72fe1465030b16e
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 12 23:29:25 2017 +0100

    Bug 779942 - Make GimpPickButton honor monitor profile
    
    Convert the picked pixel from the monitor color profile to sRGB.
    Only changed the default impl, not the quartz code.

 libgimpwidgets/gimppickbutton-default.c |   42 ++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/libgimpwidgets/gimppickbutton-default.c b/libgimpwidgets/gimppickbutton-default.c
index 07404f0..2ec270f 100644
--- a/libgimpwidgets/gimppickbutton-default.c
+++ b/libgimpwidgets/gimppickbutton-default.c
@@ -30,6 +30,7 @@
 #include "gimphelpui.h"
 #include "gimpicons.h"
 #include "gimppickbutton.h"
+#include "gimpwidgetsutils.h"
 
 #include "cursors/gimp-color-picker-cursors.c"
 
@@ -198,12 +199,14 @@ gimp_pick_button_pick (GdkScreen      *screen,
                        gint            y_root,
                        GimpPickButton *button)
 {
-  GdkWindow       *root_window = gdk_screen_get_root_window (screen);
-  cairo_surface_t *image;
-  cairo_t         *cr;
-  guchar          *data;
-  guchar           color[3];
-  GimpRGB          rgb;
+  GdkWindow        *root_window = gdk_screen_get_root_window (screen);
+  cairo_surface_t  *image;
+  cairo_t          *cr;
+  guchar           *data;
+  guchar            color[3];
+  GimpRGB           rgb;
+  GimpColorProfile *monitor_profile;
+  gint              monitor;
 
   image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);
 
@@ -221,6 +224,33 @@ gimp_pick_button_pick (GdkScreen      *screen,
 
   gimp_rgba_set_uchar (&rgb, color[0], color[1], color[2], 255);
 
+  monitor = gdk_screen_get_monitor_at_point (screen, x_root, y_root);
+  monitor_profile = gimp_screen_get_color_profile (screen, monitor);
+
+  if (monitor_profile)
+    {
+      GimpColorProfile   *srgb_profile;
+      GimpColorTransform *transform;
+      const Babl         *format;
+
+      format = babl_format ("R'G'B'A double");
+
+      srgb_profile = gimp_color_profile_new_rgb_srgb ();
+      transform = gimp_color_transform_new (monitor_profile, format,
+                                            srgb_profile,    format,
+                                            GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                            0);
+      g_object_unref (srgb_profile);
+
+      gimp_color_transform_process_pixels (transform,
+                                           format, &rgb,
+                                           format, &rgb,
+                                           1);
+      gimp_rgb_clamp (&rgb);
+
+      g_object_unref (transform);
+    }
+
   g_signal_emit_by_name (button, "color-picked", &rgb);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]