[gtk/wip/otte/colorspace: 38/50] API: Add gdk_memory_texture_new_with_color_space()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/colorspace: 38/50] API: Add gdk_memory_texture_new_with_color_space()
- Date: Thu, 28 Oct 2021 01:59:08 +0000 (UTC)
commit 995a74e1881924dca49d7b66ac68953b3954e1dd
Author: Benjamin Otte <otte redhat com>
Date: Thu Sep 23 03:26:27 2021 +0200
API: Add gdk_memory_texture_new_with_color_space()
A version of gdk_memory_texture_new() that allows passing a color
space. The old version just assumes sRGB.
gdk/gdkmemorytexture.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-----
gdk/gdkmemorytexture.h | 19 +++++++++++------
2 files changed, 63 insertions(+), 11 deletions(-)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 9827bf5cb0..e4f0893f10 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -139,6 +139,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 *
@@ -147,11 +150,51 @@ 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_space (width, height,
+ format,
+ gdk_color_space_get_srgb (),
+ bytes, stride);
+}
+
+/**
+ * gdk_memory_texture_new_with_color_space:
+ * @width: the width of the texture
+ * @height: the height of the texture
+ * @format: the format of the data
+ * @color_space: the color space for the pixels. The color space
+ * must be compatible with the format.
+ * @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`
+ *
+ * Since: 4.6
+ */
+GdkTexture *
+gdk_memory_texture_new_with_color_space (int width,
+ int height,
+ GdkMemoryFormat format,
+ GdkColorSpace *color_space,
+ 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_SPACE (color_space), NULL);
+ g_return_val_if_fail (gdk_color_space_supports_format (color_space, format), NULL);
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
@@ -160,6 +203,7 @@ gdk_memory_texture_new (int width,
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
"width", width,
"height", height,
+ "color-space", color_space,
NULL);
GDK_TEXTURE (self)->format = format;
@@ -192,11 +236,12 @@ gdk_memory_texture_new_subtexture (GdkMemoryTexture *source,
size = source->stride * (height - 1) + x * bpp;
bytes = g_bytes_new_from_bytes (source->bytes, offset, size);
- result = gdk_memory_texture_new (texture->width,
- texture->height,
- texture->format,
- bytes,
- source->stride);
+ result = gdk_memory_texture_new_with_color_space (texture->width,
+ texture->height,
+ texture->format,
+ texture->color_space,
+ bytes,
+ source->stride);
g_bytes_unref (bytes);
return result;
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 9a76c7be82..3eac45fbc3 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -60,14 +60,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkMemoryTexture, g_object_unref)
GDK_AVAILABLE_IN_ALL
-GType gdk_memory_texture_get_type (void) G_GNUC_CONST;
+GType gdk_memory_texture_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
-GdkTexture * gdk_memory_texture_new (int width,
- int height,
- GdkMemoryFormat format,
- GBytes *bytes,
- gsize stride);
+GdkTexture * gdk_memory_texture_new (int width,
+ int height,
+ GdkMemoryFormat format,
+ GBytes *bytes,
+ gsize stride);
+GDK_AVAILABLE_IN_4_6
+GdkTexture * gdk_memory_texture_new_with_color_space (int width,
+ int height,
+ GdkMemoryFormat format,
+ GdkColorSpace *color_space,
+ GBytes *bytes,
+ gsize stride);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]