summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-09-29 15:40:56 -0400
committerBenjamin Otte <otte@redhat.com>2021-10-28 03:41:09 +0200
commit5206d02a0db12107c8455bb4638d6b97069d4d73 (patch)
tree9050d9f5e3fd2930da8a01204056c911c30982cf
parente20c403f9b3c387bb3b02dd0215645ad22bd290e (diff)
downloadgtk+-5206d02a0db12107c8455bb4638d6b97069d4d73.tar.gz
Support color profiles in pixbufs
When creating a GdkTexture from a GdkPixbuf, see if it has an icc profile attached, and if so, use it.
-rw-r--r--gdk/gdktexture.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 1d3cb88443..eb0dc3975a 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -414,6 +414,30 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
return texture;
}
+static GdkColorSpace*
+gdk_color_space_get_from_pixbuf (GdkPixbuf *pixbuf)
+{
+ const char *icc_profile_base64;
+ GdkColorSpace *space = NULL;
+
+ icc_profile_base64 = gdk_pixbuf_get_option (pixbuf, "icc-profile");
+ if (icc_profile_base64)
+ {
+ guchar *icc_data;
+ gsize icc_len;
+ GBytes *bytes;
+
+ icc_data = g_base64_decode (icc_profile_base64, &icc_len);
+ bytes = g_bytes_new_take (icc_data, icc_len);
+ space = gdk_color_space_new_from_icc_profile (bytes, NULL);
+ g_bytes_unref (bytes);
+ }
+ if (!space)
+ space = g_object_ref (gdk_color_space_get_srgb ());
+
+ return space;
+}
+
/**
* gdk_texture_new_for_pixbuf:
* @pixbuf: a `GdkPixbuf`
@@ -431,23 +455,28 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
{
GdkTexture *texture;
GBytes *bytes;
+ GdkColorSpace *space;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+ space = gdk_color_space_get_from_pixbuf (pixbuf);
bytes = g_bytes_new_with_free_func (gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_height (pixbuf)
* gdk_pixbuf_get_rowstride (pixbuf),
g_object_unref,
g_object_ref (pixbuf));
- texture = gdk_memory_texture_new (gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- gdk_pixbuf_get_has_alpha (pixbuf)
- ? GDK_MEMORY_GDK_PIXBUF_ALPHA
- : GDK_MEMORY_GDK_PIXBUF_OPAQUE,
- bytes,
- gdk_pixbuf_get_rowstride (pixbuf));
+
+ texture = gdk_memory_texture_new_with_color_space (gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_has_alpha (pixbuf)
+ ? GDK_MEMORY_GDK_PIXBUF_ALPHA
+ : GDK_MEMORY_GDK_PIXBUF_OPAQUE,
+ space,
+ bytes,
+ gdk_pixbuf_get_rowstride (pixbuf));
g_bytes_unref (bytes);
+ g_object_unref (space);
return texture;
}