[gtk/wip/otte/colorspace: 47/59] texture: Add a ::color-space property




commit 09bdc94995d9d8644298e74b598ec8f281929882
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 20 09:44:32 2021 +0200

    texture: Add a ::color-space property
    
    Returns the associated color space. For now, this is always sRGB.

 gdk/gdktexture.c        | 93 ++++++++++++++++++++++++++++++++++++++++---------
 gdk/gdktexture.h        |  2 ++
 gdk/gdktextureprivate.h |  1 +
 3 files changed, 79 insertions(+), 17 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index e5b68ee5c3..9555f7822e 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -31,6 +31,11 @@
  * instance; you can only make a copy of it, via [method@Gdk.Texture.download]
  * or [method@Gdk.Texture.download_float].
  *
+ * A `GdkColorSpace` is part of every GdkTexture that describes the internal
+ * representation of the pixel data. This is most relevant when creating
+ * textures yourself as you can choose the color space you provide your
+ * pixel data in.
+ *
  * `GdkTexture` is an immutable object: That means you cannot change
  * anything about it other than increasing the reference count via
  * g_object_ref().
@@ -40,6 +45,7 @@
 
 #include "gdktextureprivate.h"
 
+#include "gdkcolorspace.h"
 #include "gdkintl.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdkpaintable.h"
@@ -60,8 +66,9 @@ gtk_snapshot_append_texture (GdkSnapshot            *snapshot,
 
 enum {
   PROP_0,
-  PROP_WIDTH,
+  PROP_COLOR_SPACE,
   PROP_HEIGHT,
+  PROP_WIDTH,
 
   N_PROPS
 };
@@ -240,14 +247,20 @@ gdk_texture_set_property (GObject      *gobject,
 
   switch (prop_id)
     {
-    case PROP_WIDTH:
-      self->width = g_value_get_int (value);
+    case PROP_COLOR_SPACE:
+      self->color_space = g_value_dup_object (value);
+      if (self->color_space == NULL)
+        self->color_space = g_object_ref (gdk_color_space_get_srgb ());
       break;
 
     case PROP_HEIGHT:
       self->height = g_value_get_int (value);
       break;
 
+    case PROP_WIDTH:
+      self->width = g_value_get_int (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -264,14 +277,18 @@ gdk_texture_get_property (GObject    *gobject,
 
   switch (prop_id)
     {
-    case PROP_WIDTH:
-      g_value_set_int (value, self->width);
+    case PROP_COLOR_SPACE:
+      g_value_set_object (value, self->color_space);
       break;
 
     case PROP_HEIGHT:
       g_value_set_int (value, self->height);
       break;
 
+    case PROP_WIDTH:
+      g_value_set_int (value, self->width);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -284,6 +301,7 @@ gdk_texture_dispose (GObject *object)
   GdkTexture *self = GDK_TEXTURE (object);
 
   gdk_texture_clear_render_data (self);
+  g_clear_object (&self->color_space);
 
   G_OBJECT_CLASS (gdk_texture_parent_class)->dispose (object);
 }
@@ -300,14 +318,31 @@ gdk_texture_class_init (GdkTextureClass *klass)
   gobject_class->dispose = gdk_texture_dispose;
 
   /**
-   * GdkTexture:width: (attributes org.gtk.Property.get=gdk_texture_get_width)
+   * GdkTexture:color-space: (attributes org.gtk.Property.get=gdk_texture_get_color_space)
    *
-   * The width of the texture, in pixels.
+   * The color space associated with texture.
+   *
+   * Since: 4.6
    */
-  properties[PROP_WIDTH] =
-    g_param_spec_int ("width",
-                      "Width",
-                      "The width of the texture",
+  properties[PROP_COLOR_SPACE] =
+    g_param_spec_object ("color-space",
+                         P_("Color Space"),
+                         P_("The associated color space"),
+                         GDK_TYPE_COLOR_SPACE,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * GdkTexture:height: (attributes org.gtk.Property.get=gdk_texture_get_height)
+   *
+   * The height of the texture, in pixels.
+   */
+  properties[PROP_HEIGHT] =
+    g_param_spec_int ("height",
+                      P_("Height"),
+                      P_("The height of the texture"),
                       1,
                       G_MAXINT,
                       1,
@@ -317,14 +352,14 @@ gdk_texture_class_init (GdkTextureClass *klass)
                       G_PARAM_EXPLICIT_NOTIFY);
 
   /**
-   * GdkTexture:height: (attributes org.gtk.Property.get=gdk_texture_get_height)
+   * GdkTexture:width: (attributes org.gtk.Property.get=gdk_texture_get_width)
    *
-   * The height of the texture, in pixels.
+   * The width of the texture, in pixels.
    */
-  properties[PROP_HEIGHT] =
-    g_param_spec_int ("height",
-                      "Height",
-                      "The height of the texture",
+  properties[PROP_WIDTH] =
+    g_param_spec_int ("width",
+                      P_("Width"),
+                      P_("The width of the texture"),
                       1,
                       G_MAXINT,
                       1,
@@ -668,6 +703,24 @@ gdk_texture_get_height (GdkTexture *texture)
   return texture->height;
 }
 
+/**
+ * gdk_texture_get_color_space: (attributes org.gtk.Method.get_property=color-space)
+ * @texture: a `GdkTexture`
+ *
+ * Returns the color space associated with @texture.
+ *
+ * Returns: (transfer none): the color space of the `GdkTexture`
+ *
+ * Since: 4.6
+ */
+GdkColorSpace *
+gdk_texture_get_color_space (GdkTexture *texture)
+{
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
+
+  return texture->color_space;
+}
+
 void
 gdk_texture_do_download (GdkTexture      *texture,
                          GdkMemoryFormat  format,
@@ -715,6 +768,9 @@ gdk_texture_download_surface (GdkTexture *texture)
  * %CAIRO_FORMAT_ARGB32, so every downloaded pixel requires
  * 4 bytes of memory.
  *
+ * The downloaded data will be in the sRGB color space, no matter the
+ * color space of the texture.
+ *
  * Downloading a texture into a Cairo image surface:
  * ```c
  * surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
@@ -756,6 +812,9 @@ gdk_texture_download (GdkTexture *texture,
  * may need to be upsampled if it was not already available in this
  * format.
  *
+ * The downloaded data will be in the sRGB color space, no matter the
+ * color space of the texture.
+ *
  * You may want to use [method@Gdk.Texture.download] instead if you don't
  * need high dynamic range support.
  *
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 6a62c9fe50..e1a034e3f2 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -84,6 +84,8 @@ GDK_AVAILABLE_IN_ALL
 int                     gdk_texture_get_width                  (GdkTexture      *texture) G_GNUC_PURE;
 GDK_AVAILABLE_IN_ALL
 int                     gdk_texture_get_height                 (GdkTexture      *texture) G_GNUC_PURE;
+GDK_AVAILABLE_IN_4_6
+GdkColorSpace *         gdk_texture_get_color_space            (GdkTexture      *texture) G_GNUC_PURE;
 
 GDK_AVAILABLE_IN_ALL
 void                    gdk_texture_download                   (GdkTexture      *texture,
diff --git a/gdk/gdktextureprivate.h b/gdk/gdktextureprivate.h
index d9579f4657..57171adeb8 100644
--- a/gdk/gdktextureprivate.h
+++ b/gdk/gdktextureprivate.h
@@ -16,6 +16,7 @@ struct _GdkTexture
   GdkMemoryFormat format;
   int width;
   int height;
+  GdkColorSpace *color_space;
 
   gpointer render_key;
   gpointer render_data;


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