# HG changeset patch # User Olaf Wintermann # Date 1744878469 -7200 # Node ID 4ee3e4ce03ad2082480c145a4e8ce5131f532624 # Parent 0e0e9035c6c72bd2c3aeda9ccaea60825485868e# Parent 54a97e5433896f907e873f4fb62480d9614c66b7 merge diff -r 0e0e9035c6c7 -r 4ee3e4ce03ad ui/gtk/image.c --- a/ui/gtk/image.c Thu Apr 17 10:25:41 2025 +0200 +++ b/ui/gtk/image.c Thu Apr 17 10:27:49 2025 +0200 @@ -341,6 +341,26 @@ 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(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 0e0e9035c6c7 -r 4ee3e4ce03ad ui/ui/image.h --- a/ui/ui/image.h Thu Apr 17 10:25:41 2025 +0200 +++ b/ui/ui/image.h Thu Apr 17 10:27:49 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);