Browse Source

Refactor gallery loading, misc

Ruben 1 year ago
parent
commit
0eb8d87b8c

+ 4 - 2
src/PicView.Avalonia/PicView.Avalonia.csproj

@@ -8,16 +8,18 @@
     <Company>Ruben Hyldgaard Negendahl</Company>
     <Product>PicView</Product>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <PlatformTarget>ARM64</PlatformTarget>
+    <PlatformTarget>X64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
     <IsAotCompatible>False</IsAotCompatible>
     <IsTrimmable>True</IsTrimmable>
+    <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
     <IsAotCompatible>True</IsAotCompatible>
     <IsTrimmable>True</IsTrimmable>
 	  <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+	  <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   <PropertyGroup Label="Avalonia">
     <AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
@@ -56,7 +58,7 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-rc1" />
     <PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0-beta1" />
-    <PackageReference Include="Magick.NET-Q8-arm64" Version="13.9.1" />
+    <PackageReference Include="Magick.NET-Q8-OpenMP-x64" Version="13.9.1" />
   </ItemGroup>
 
   <ItemGroup>

+ 2 - 2
src/PicView.Core/PicView.Core.csproj

@@ -11,7 +11,7 @@
     <IsAotCompatible>True</IsAotCompatible>
     <IsTrimmable>True</IsTrimmable>
     <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
-    <PlatformTarget>ARM64</PlatformTarget>
+    <PlatformTarget>X64</PlatformTarget>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -23,7 +23,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Magick.NET-Q8-arm64" Version="13.9.1" />
+    <PackageReference Include="Magick.NET-Q8-OpenMP-x64" Version="13.9.1" />
   </ItemGroup>
 
   <ItemGroup>

+ 2 - 2
src/PicView.WPF/ChangeImage/FileUpdateNavigation.cs

@@ -91,7 +91,7 @@ internal static class FileUpdateNavigation
         {
             await Task.Delay(100);
         }
-        var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(index, null, fileInfo);
+        var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(fileInfo);
         await UC.GetPicGallery?.Dispatcher?.InvokeAsync(() =>
         {
             var item = UC.GetPicGallery.Container.Children.OfType<PicGalleryItem>().FirstOrDefault(x => x.FilePath == oldPath);
@@ -331,7 +331,7 @@ internal static class FileUpdateNavigation
             }
             var thumbSource = await Thumbnails.GetBitmapSourceThumbAsync(e.FullPath,
                 (int)GalleryNavigation.PicGalleryItemSize, fileInfo).ConfigureAwait(false);
-            var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(index, new Image2BitmapSource.WpfImageSource(thumbSource), fileInfo);
+            var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(fileInfo);
             await UC.GetPicGallery?.Dispatcher?.InvokeAsync(() =>
             {
                 var item = new PicGalleryItem(thumbSource, e.FullPath, false)

+ 1 - 1
src/PicView.WPF/FileHandling/OpenSave.cs

@@ -247,7 +247,7 @@ internal static class OpenSave
                     var fileInfo = new FileInfo(Pics[FolderIndex]);
                     var bitmapSource = await Thumbnails.GetBitmapSourceThumbAsync(Pics[FolderIndex],
                         (int)GalleryNavigation.PicGalleryItemSize, fileInfo).ConfigureAwait(false);
-                    var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(FolderIndex, new Image2BitmapSource.WpfImageSource(bitmapSource), fileInfo);
+                    var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(fileInfo);
                     await GetPicGallery.Dispatcher.InvokeAsync(() =>
                     {
                         UpdatePic(FolderIndex, bitmapSource,

+ 0 - 11
src/PicView.WPF/ImageHandling/Image2BitmapSource.cs

@@ -214,15 +214,4 @@ internal static class Image2BitmapSource
         bitmap.Freeze();
         return bitmap;
     }
-
-    public class WpfImageSource(BitmapSource? bitmapSource) : GalleryThumbInfo.IImageSource
-    {
-        private readonly BitmapSource _bitmapSource = bitmapSource ?? ImageFunctions.ImageErrorMessage() ??
-            throw new ArgumentNullException(nameof(bitmapSource));
-
-        public object GetPlatformImageSource()
-        {
-            return _bitmapSource;
-        }
-    }
 }

+ 18 - 5
src/PicView.WPF/PicGallery/GalleryFunctions.cs

@@ -20,6 +20,20 @@ internal static class GalleryFunctions
 {
     internal static bool IsGalleryOpen { get; set; }
 
+    private struct TempGalleryItem(
+        string fileLocation,
+        string fileName,
+        string fileSize,
+        string fileDate,
+        BitmapSource source)
+    {
+        internal string FileLocation = fileLocation;
+        internal string FileName = fileName;
+        internal string FileSize = fileSize;
+        internal string FileDate = fileDate;
+        internal BitmapSource Source { get; set; } = source;
+    }
+
     internal static void ReCalculateItemSizes()
     {
         if (GetPicGallery is null)
@@ -79,7 +93,7 @@ internal static class GalleryFunctions
             }
         }
 
-        var thumbs = new List<GalleryThumbInfo.GalleryThumbHolder>();
+        var thumbs = new List<TempGalleryItem>();
 
         for (var i = 0; i < Navigation.Pics.Count; i++)
         {
@@ -92,10 +106,9 @@ internal static class GalleryFunctions
                         return;
                     }
                     var picGalleryItem = GetPicGallery.Container.Children[i] as PicGalleryItem;
-                    var bitmapSource = new Image2BitmapSource.WpfImageSource(picGalleryItem.ThumbImage?.Source as BitmapSource);
-                    var thumb = new GalleryThumbInfo.GalleryThumbHolder(picGalleryItem.ThumbFileLocation.Text,
+                    var thumb = new TempGalleryItem(picGalleryItem.ThumbFileLocation.Text,
                         picGalleryItem.ThumbFileName.Text, picGalleryItem.ThumbFileSize.Text,
-                        picGalleryItem.ThumbFileDate.Text, bitmapSource);
+                        picGalleryItem.ThumbFileDate.Text, picGalleryItem.ThumbImage.Source as BitmapSource);
                     thumbs.Add(thumb);
                 }, DispatcherPriority.Render, cancellationTokenSource.Token);
                 if (initialDirectory != Path.GetDirectoryName(Navigation.Pics[0]))
@@ -127,7 +140,7 @@ internal static class GalleryFunctions
                 var index = i;
                 await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
                 {
-                    UpdatePic(index, (BitmapSource?)thumbs[index].ImageSource, thumbs[index].FileLocation, thumbs[index].FileName,
+                    UpdatePic(index, (BitmapSource?)thumbs[index].Source, thumbs[index].FileLocation, thumbs[index].FileName,
                         thumbs[index].FileSize, thumbs[index].FileDate);
                     GalleryNavigation.SetSelected(index, index == Navigation.FolderIndex);
                 }, DispatcherPriority.Background, cancellationTokenSource.Token);

+ 1 - 2
src/PicView.WPF/PicGallery/GalleryLoad.cs

@@ -189,8 +189,7 @@ internal static class GalleryLoad
             var fileInfo = new FileInfo(Navigation.Pics[i]);
             var bitmapSource = await Thumbnails.GetBitmapSourceThumbAsync(Navigation.Pics[i],
                 (int)GalleryNavigation.PicGalleryItemSize, fileInfo).ConfigureAwait(false);
-            var converted = new Image2BitmapSource.WpfImageSource(bitmapSource);
-            var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(i, converted, fileInfo);
+            var thumbData = GalleryThumbInfo.GalleryThumbHolder.GetThumbData(fileInfo);
             await UC.GetPicGallery.Dispatcher.InvokeAsync(() =>
             {
                 UpdatePic(i, bitmapSource, thumbData.FileLocation,