# HG changeset patch # User Olaf Wintermann # Date 1744576226 -7200 # Node ID 6fc93c3b91c9c5de7159fba878f67da5cbdda88c # Parent 5798e3a28c595af791f080b08afbd1f5c8cc5eb3 add ui_image_load_data (GTK) diff -r 5798e3a28c59 -r 6fc93c3b91c9 ui/gtk/image.c --- a/ui/gtk/image.c Thu Apr 10 21:18:14 2025 +0200 +++ b/ui/gtk/image.c Sun Apr 13 22:30:26 2025 +0200 @@ -341,6 +341,27 @@ return 0; } +UIEXPORT int ui_image_load_data(UiGeneric *obj, const void *imgdata, size_t size) { + GBytes *bytes = g_bytes_new_static(imgdata, size); + GInputStream *in = g_memory_input_stream_new_from_bytes(bytes); + GError *error = NULL; + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(in, NULL, &error); + g_object_unref(bytes); + g_object_unref(in); + if(!pixbuf) { + return 1; + } + + if(obj->set) { + obj->set(obj, pixbuf, UI_IMAGE_OBJECT_TYPE); + g_object_unref(pixbuf); + } else { + obj->value = pixbuf; + } + + return 0; +} + void ui_image_ref(UIIMAGE img) { g_object_ref(img); } diff -r 5798e3a28c59 -r 6fc93c3b91c9 ui/ui/image.h --- a/ui/ui/image.h Thu Apr 10 21:18:14 2025 +0200 +++ b/ui/ui/image.h Sun Apr 13 22:30:26 2025 +0200 @@ -85,6 +85,7 @@ UIEXPORT UIWIDGET ui_imageviewer_set_useradjustable(UIWIDGET w, UiBool set); UIEXPORT int ui_image_load_file(UiGeneric *obj, const char *path); +UIEXPORT int ui_image_load_data(UiGeneric *obj, const void *imgdata, size_t size); UIEXPORT void ui_image_ref(UIIMAGE img); UIEXPORT void ui_image_unref(UIIMAGE img);