[gtk/gamma-shenanigans] Switch to downloading GdkRGBA



commit e63b8d0a7cf5741b6511195d504c920a2762a831
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 8 10:29:38 2021 -0400

    Switch to downloading GdkRGBA

 gdk/gdktexture.c | 32 +++++++++++++++++++++++---------
 gdk/gdktexture.h |  4 ++--
 2 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index ead32c3a3b..6f6b3eab9e 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -44,6 +44,7 @@
 #include "gdkmemorytextureprivate.h"
 #include "gdkpaintable.h"
 #include "gdksnapshot.h"
+#include "gdkrgba.h"
 
 #include <graphene.h>
 #include <png.h>
@@ -662,7 +663,7 @@ gdk_texture_convert_format (GdkTexture      *texture,
 }
 
 /*
- * gdk_texture_download_float:
+ * gdk_texture_download_hdr:
  * @texture: a `GdkTexture`
  * @data: (array): pointer to enough memory to be filled with the
  *   downloaded data of @texture
@@ -672,18 +673,13 @@ gdk_texture_convert_format (GdkTexture      *texture,
  * This may be an expensive operation, as the actual texture data
  * may reside on a GPU or on a remote display server.
  *
- * The data format of the downloaded data is equivalent to
- * GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, so every downloaded
- * pixel requires 16 bytes of memory.
- *
- * Note that the caller is responsible to provide sufficiently
- * aligned memory to access the resulting data directly as floats.
+ * The data is stored in an array of `GdkRGBA` structs.
  *
  * Since: 4.6
  */
 void
-gdk_texture_download_float (GdkTexture *texture,
-                            float      *data)
+gdk_texture_download_hdr (GdkTexture *texture,
+                          GdkRGBA    *data)
 {
   GBytes *bytes;
 
@@ -691,7 +687,25 @@ gdk_texture_download_float (GdkTexture *texture,
 
   g_assert (bytes);
 
+#if 0
+  /* FIXME: add an unpremultiplied format */
   memcpy (data, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
+#else
+  int width = gdk_texture_get_width (texture);
+  int height = gdk_texture_get_height (texture);
+
+  for (int y = 0; y < height; y++)
+    for (int x = 0; x < width; x++)
+      {
+        GdkRGBA *c = &data[y * height + x];
+        if (c->alpha != 0)
+          {
+            c->red /= c->alpha;
+            c->green /= c->alpha;
+            c->blue /= c->alpha;
+          }
+      }
+#endif
 
   g_bytes_unref (bytes);
 }
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 1547cce23a..067592156b 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -60,8 +60,8 @@ void                    gdk_texture_download                   (GdkTexture
                                                                 guchar          *data,
                                                                 gsize            stride);
 GDK_AVAILABLE_IN_4_6
-void                    gdk_texture_download_float             (GdkTexture      *texture,
-                                                                float           *data);
+void                    gdk_texture_download_hdr               (GdkTexture      *texture,
+                                                                GdkRGBA         *data);
 GDK_AVAILABLE_IN_ALL
 gboolean                gdk_texture_save_to_png                (GdkTexture      *texture,
                                                                 const char      *filename);


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