[gtk/matthiasc/color-profile-rebased: 836/875] API: Add gdk_memory_texture_new_with_color_space()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 836/875] API: Add gdk_memory_texture_new_with_color_space()
- Date: Wed, 28 Sep 2022 18:51:53 +0000 (UTC)
commit 006f473039c398861403d11cf482f70ad061580a
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 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 1ecd2978cd..6d06ba971c 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -21,6 +21,7 @@
#include "gdkmemorytextureprivate.h"
+#include "gdkcolorspaceprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkcolorspaceprivate.h"
#include "gsk/gl/fp16private.h"
@@ -137,6 +138,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_space]
+ * with the sRGB color space.
+ *
* Returns: (type GdkMemoryTexture): A newly-created `GdkTexture`
*/
GdkTexture *
@@ -145,19 +149,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_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: a `GdkColorSpace`
+ * @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 space.
+ *
+ * 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_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 (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_space_supports_format (color_space, 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-space", color_space,
NULL);
GDK_TEXTURE (self)->format = format;
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 9a76c7be82..e58ac38a30 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -26,6 +26,7 @@
#include <gdk/gdkenums.h>
#include <gdk/gdktexture.h>
+#include <gdk/gdkcolorspace.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_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]