[gtk/matthiasc/color-profile-rebased: 4/46] API: Add gdk_memory_texture_new_with_color_profile()




commit 5eda3eee87b86233cf0098ceecdc417c0c2e0212
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 | 44 ++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkmemorytexture.h |  9 +++++++++
 2 files changed, 53 insertions(+)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index c9aecd5cea..2bf9fb3a27 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -21,6 +21,7 @@
 
 #include "gdkmemorytextureprivate.h"
 
+#include "gdkcolorprofileprivate.h"
 #include "gdkmemoryformatprivate.h"
 #include "gsk/gl/fp16private.h"
 
@@ -136,6 +137,9 @@ gdk_memory_sanitize (GBytes          *bytes,
  * The `GBytes` must contain @stride × @height pixels
  * in the given format.
  *
+ * This function calls [ctor@Gdk.MemoryTexture.new_with_color_profile]
+ * with the sRGB profile.
+ *
  * Returns: (type GdkMemoryTexture): A newly-created `GdkTexture`
  */
 GdkTexture *
@@ -144,19 +148,59 @@ 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
+ * @profile: a `GdkColorProfile`
+ * @bytes: the `GBytes` containing the pixel data
+ * @stride: rowstride for the data
+ *
+ * Creates a new texture for a blob of image data with a given color profile.
+ *
+ * The `GBytes` must contain @stride x @height pixels
+ * in the given format.
+ *
+ * Returns: A newly-created `GdkTexture`
+ *
+ * Since: 4.8
+ */
+GdkTexture *
+gdk_memory_texture_new_with_color_profile (int              width,
+                                           int              height,
+                                           GdkMemoryFormat  format,
+                                           GdkColorProfile *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 (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);
+  g_return_val_if_fail (gdk_color_profile_supports_memory_format (profile, format), NULL);
 
   bytes = gdk_memory_sanitize (bytes, width, height, format, stride, &stride);
 
   self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
                        "width", width,
                        "height", height,
+                       "color-profile", profile,
                        NULL);
 
   GDK_TEXTURE (self)->format = format;
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 9a76c7be82..8027664526 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -26,6 +26,7 @@
 
 #include <gdk/gdkenums.h>
 #include <gdk/gdktexture.h>
+#include <gdk/gdkcolorprofile.h>
 
 G_BEGIN_DECLS
 
@@ -68,6 +69,14 @@ GdkTexture *            gdk_memory_texture_new              (int
                                                              GdkMemoryFormat    format,
                                                              GBytes            *bytes,
                                                              gsize              stride);
+GDK_AVAILABLE_IN_4_8
+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]