diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c index 0e8e2cc78d..b4380482de 100644 --- a/gdk/gdkmemorytexture.c +++ b/gdk/gdkmemorytexture.c @@ -22,6 +22,7 @@ #include "gdkmemorytextureprivate.h" #include "gdkmemoryformatprivate.h" +#include "gdkcolorstate.h" #include "gsk/gl/fp16private.h" /** @@ -131,7 +132,7 @@ gdk_memory_sanitize (GBytes *bytes, * @bytes: the `GBytes` containing the pixel data * @stride: rowstride for the data * - * Creates a new texture for a blob of image data. + * Creates a new texture for a blob of sRGB image data. * * The `GBytes` must contain @stride × @height pixels * in the given format. @@ -144,11 +145,43 @@ gdk_memory_texture_new (int width, GdkMemoryFormat format, GBytes *bytes, gsize stride) +{ + return gdk_memory_texture_new_with_color_state (width, height, format, + gdk_color_state_get_srgb (), + bytes, stride); +} + +/** + * gdk_memory_texture_new_with_color_state: + * @width: the width of the texture + * @height: the height of the texture + * @format: the format of the data + * @color_state: 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 state. + * + * The `GBytes` must contain @stride x @height pixels + * in the given format. + * + * Returns: A newly-created `GdkTexture` + * + * Since: 4.16 + */ +GdkTexture * +gdk_memory_texture_new_with_color_state (int width, + int height, + GdkMemoryFormat format, + GdkColorState *color_state, + 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 (color_state != NULL, NULL); g_return_val_if_fail (bytes != NULL, NULL); g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL); /* needs to be this complex to support subtexture of the bottom right part */ @@ -159,6 +192,7 @@ gdk_memory_texture_new (int width, self = g_object_new (GDK_TYPE_MEMORY_TEXTURE, "width", width, "height", height, + "color-state", color_state, NULL); GDK_TEXTURE (self)->format = format; @@ -191,11 +225,12 @@ gdk_memory_texture_new_subtexture (GdkMemoryTexture *source, size = source->stride * (height - 1) + width * bpp; bytes = g_bytes_new_from_bytes (source->bytes, offset, size); - result = gdk_memory_texture_new (width, - height, - texture->format, - bytes, - source->stride); + result = gdk_memory_texture_new_with_color_state (width, + height, + texture->format, + texture->color_state, + bytes, + source->stride); g_bytes_unref (bytes); return result; @@ -225,11 +260,12 @@ gdk_memory_texture_from_texture (GdkTexture *texture, gdk_texture_do_download (texture, format, data, stride); bytes = g_bytes_new_take (data, stride * texture->height); - result = gdk_memory_texture_new (texture->width, - texture->height, - format, - bytes, - stride); + result = gdk_memory_texture_new_with_color_state (texture->width, + texture->height, + format, + texture->color_state, + bytes, + stride); g_bytes_unref (bytes); return GDK_MEMORY_TEXTURE (result); diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h index 21ecc6a96b..cb7a47d7c4 100644 --- a/gdk/gdkmemorytexture.h +++ b/gdk/gdkmemorytexture.h @@ -68,6 +68,14 @@ GdkTexture * gdk_memory_texture_new (int GBytes *bytes, gsize stride); +GDK_AVAILABLE_IN_4_16 +GdkTexture * gdk_memory_texture_new_with_color_state (int width, + int height, + GdkMemoryFormat format, + GdkColorState *color_state, + GBytes *bytes, + gsize stride); + G_END_DECLS