ui/winui/image.cpp

changeset 613
dac25dd922a2
parent 375
af087d0fad9b
child 614
a6e70dead6bd
--- a/ui/winui/image.cpp	Mon Jun 09 08:47:57 2025 +0200
+++ b/ui/winui/image.cpp	Tue Jun 10 12:28:30 2025 +0200
@@ -47,6 +47,16 @@
 
 UiImageSource::UiImageSource(winrt::Microsoft::UI::Xaml::Media::ImageSource& src) : imgsrc(src) {}
 
+void UiImageSource::ref() {
+	refcount++;
+}
+
+void UiImageSource::unref() {
+	if (--refcount == 0) {
+		delete this;
+	}
+}
+
 UIEXPORT UIWIDGET ui_imageviewer_create(UiObject *obj, UiImageViewerArgs args) {
     UiObject* current = uic_current_obj(obj);
     
@@ -94,9 +104,10 @@
     UiImageSource *imgdata = (UiImageSource*)data;
     if (g->value) {
         UiImageSource *prevData = (UiImageSource*)g->value;
-        delete prevData;
+        //prevData->unref();
     }
     g->value = imgdata;
+    //imgdata->ref();
 
     UiWidget* widget = (UiWidget*)g->obj;
     Image image = widget->uielement.as<Image>();
@@ -111,14 +122,25 @@
     std::wstring uriPath = L"file:///" + wPath;
     Uri uri{ uriPath };
     
-    BitmapImage bitmapImage = BitmapImage();
+    BitmapImage bitmapImage = BitmapImage();UiImageSource
     bitmapImage.UriSource(uri);
     ImageSource src = bitmapImage;
 
     UiImageSource *imgdata = new UiImageSource(src);
     obj->set(obj, imgdata, UI_IMAGE_OBJECT_TYPE);
+    imgdata->unref();
 
     free(wpath);
 
     return 0;
 }
+
+void ui_image_ref(UIIMAGE img) {
+    UiImageSource* imgdata = (UiImageSource*)img;
+    imgdata->ref();
+}
+
+void ui_image_unref(UIIMAGE img) {
+    UiImageSource* imgdata = (UiImageSource*)img;
+    imgdata->unref();
+}

mercurial