[gtk/wip/otte/color-profiles] FIXME: Add a crude way to color-correct GdkRGBAs



commit a040164aa0f6bf2ae7cf896a49f573861634a7c5
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 26 03:03:45 2021 +0200

    FIXME: Add a crude way to color-correct GdkRGBAs
    
    Only used in gdk_cairo_set_source_rgba() for now, but works as a proof
    of concept.

 gdk/gdkcairo.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index 1f1eb58a61..3a60999871 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -20,9 +20,28 @@
 #include "gdkcairoprivate.h"
 
 #include "gdkcolorprofile.h"
+#include "gdkmemoryformatprivate.h"
 
 #include <math.h>
 
+static void
+gdk_rgba_convert (GdkRGBA         *dest,
+                  const GdkRGBA   *src,
+                  GdkColorProfile *profile)
+{
+  gdk_memory_convert ((guchar *) dest,
+                      sizeof (float) * 4,
+                      GDK_MEMORY_R32G32B32_FLOAT,
+                      profile,
+                      (guchar *) src,
+                      sizeof (float) * 4,
+                      GDK_MEMORY_R32G32B32_FLOAT,
+                      gdk_color_profile_get_srgb (),
+                      1,
+                      1);
+  dest->alpha = src->alpha;
+}
+
 /**
  * gdk_cairo_set_source_rgba:
  * @cr: a cairo context
@@ -34,14 +53,17 @@ void
 gdk_cairo_set_source_rgba (cairo_t       *cr,
                            const GdkRGBA *rgba)
 {
+  GdkRGBA tmp;
+
   g_return_if_fail (cr != NULL);
   g_return_if_fail (rgba != NULL);
 
+  gdk_rgba_convert (&tmp, rgba, gdk_cairo_get_color_profile (cr));
   cairo_set_source_rgba (cr,
-                         rgba->red,
-                         rgba->green,
-                         rgba->blue,
-                         rgba->alpha);
+                         tmp.red,
+                         tmp.green,
+                         tmp.blue,
+                         tmp.alpha);
 }
 
 /**


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