[gtk/wip/otte/color-profiles: 17/22] API: Add gdk_memory_texture_new_with_color_profile()




commit aad9752511d91f60fe8c37582f1d8427f0ccb9e3
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 23 03:26:27 2021 +0200

    API: Add gdk_memory_texture_new_with_color_profile()
    
    A version of gdk_memory_texture_new() that allows passing a color
    profile. The old version t assumes sRGB.

 gdk/gdkmemorytexture.c | 39 +++++++++++++++++++++++++++++++++++++++
 gdk/gdkmemorytexture.h |  8 ++++++++
 2 files changed, 47 insertions(+)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 61ac5d31fc..3f64b423f3 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -166,6 +166,9 @@ gdk_memory_sanitize (GBytes          *bytes,
  * The `GBytes` must contain @stride x @height pixels
  * in the given format.
  *
+ * This function calls [ctor@Gdk.MemoryTexture.new_with_color_profile]
+ * with the sRGB profile.
+ *
  * Returns: A newly-created `GdkTexture`
  */
 GdkTexture *
@@ -174,11 +177,46 @@ gdk_memory_texture_new (int              width,
                         GdkMemoryFormat  format,
                         GBytes          *bytes,
                         gsize            stride)
+{
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
+  g_return_val_if_fail (bytes != NULL, NULL);
+  g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
+
+  return gdk_memory_texture_new_with_color_profile (width, height,
+                                                    format,
+                                                    gdk_color_profile_get_srgb (),
+                                                    bytes, stride);
+}
+
+/**
+ * gdk_memory_texture_new_with_color_profile:
+ * @width: the width of the texture
+ * @height: the height of the texture
+ * @format: the format of the data
+ * @bytes: the `GBytes` containing the pixel data
+ * @stride: rowstride for the data
+ *
+ * Creates a new texture for a blob of image data.
+ *
+ * The `GBytes` must contain @stride x @height pixels
+ * in the given format.
+ *
+ * Returns: A newly-created `GdkTexture`
+ */
+GdkTexture *
+gdk_memory_texture_new_with_color_profile (int              width,
+                                           int              height,
+                                           GdkMemoryFormat  format,
+                                           GdkColorProfile *color_profile,
+                                           GBytes          *bytes,
+                                           gsize            stride)
 {
   GdkMemoryTexture *self;
 
   g_return_val_if_fail (width > 0, NULL);
   g_return_val_if_fail (height > 0, NULL);
+  g_return_val_if_fail (GDK_IS_COLOR_PROFILE (color_profile), NULL);
   g_return_val_if_fail (bytes != NULL, NULL);
   g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
 
@@ -187,6 +225,7 @@ gdk_memory_texture_new (int              width,
   self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
                        "width", width,
                        "height", height,
+                       "color-profile", color_profile,
                        NULL);
 
   self->format = format;
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 114922153e..f5f0198991 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -130,6 +130,14 @@ GdkTexture *            gdk_memory_texture_new              (int
                                                              GdkMemoryFormat    format,
                                                              GBytes            *bytes,
                                                              gsize              stride);
+GDK_AVAILABLE_IN_4_6
+GdkTexture *            gdk_memory_texture_new_with_color_profile
+                                                            (int                width,
+                                                             int                height,
+                                                             GdkMemoryFormat    format,
+                                                             GdkColorProfile   *profile,
+                                                             GBytes            *bytes,
+                                                             gsize              stride);
 
 
 G_END_DECLS


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