Răsfoiți Sursa

Refactor, rename

Ruben 2 ani în urmă
părinte
comite
f82fb1cff8

+ 29 - 1
PicView/ImageHandling/ImageSizeFunctions.cs

@@ -7,6 +7,11 @@ namespace PicView.ImageHandling;
 
 internal static class ImageSizeFunctions
 {
+    /// <summary>
+    /// Gets the size of an image file.
+    /// </summary>
+    /// <param name="file">The path of the image file.</param>
+    /// <returns>The size of the image if the file exists and the size can be determined; otherwise, null.</returns>
     internal static Size? GetImageSize(string file)
     {
         if (!File.Exists(file))
@@ -38,6 +43,18 @@ internal static class ImageSizeFunctions
         return new Size(magick.Width, magick.Height);
     }
 
+    /// <summary>
+    /// Resizes an image asynchronously with optional compression and format conversion.
+    /// </summary>
+    /// <param name="fileInfo">The FileInfo of the image file to resize.</param>
+    /// <param name="width">The target width of the image.</param>
+    /// <param name="height">The target height of the image.</param>
+    /// <param name="quality">The quality level of the image.</param>
+    /// <param name="percentage">The percentage value to resize the image.</param>
+    /// <param name="destination">The path of the destination file to save the resized image.</param>
+    /// <param name="compress">Indicates whether to compress the image.</param>
+    /// <param name="ext">The file extension of the output image.</param>
+    /// <returns>True if the image is resized and saved successfully; otherwise, false.</returns>
     internal static async Task<bool> ResizeImageAsync(FileInfo fileInfo, int width, int height, int quality = 100, Percentage? percentage = null, string? destination = null, bool? compress = null, string? ext = null)
     {
         if (fileInfo.Exists == false) { return false; }
@@ -84,6 +101,17 @@ internal static class ImageSizeFunctions
                 if (ext is not null)
                 {
                     Path.ChangeExtension(fileInfo.Extension, ext);
+                    switch (Path.GetExtension(ext).ToLowerInvariant())
+                    {
+                        case ".jpeg":
+                        case ".jpg": magick.Format = MagickFormat.Jpeg; break;
+                        case ".png": magick.Format = MagickFormat.Png; break;
+                        case ".jxl": magick.Format = MagickFormat.Jxl; break;
+                        case ".gif": magick.Format = MagickFormat.Gif; break;
+                        case ".webp": magick.Format = MagickFormat.WebP; break;
+                        case ".heic": magick.Format = MagickFormat.Heic; break;
+                        case ".heif": magick.Format = MagickFormat.Heif; break;
+                    }
                 }
                 await magick.WriteAsync(fileInfo).ConfigureAwait(false);
             }
@@ -135,4 +163,4 @@ internal static class ImageSizeFunctions
 
         return true;
     }
-}
+}

+ 19 - 18
PicView/PicGallery/GalleryClick.cs

@@ -35,51 +35,51 @@ internal static class GalleryClick
         {
             ConfigureWindows.GetMainWindow.Focus();
             ConfigureWindows.GetMainWindow.MainImage.Visibility = Visibility.Hidden;
-            var z = GetPicGallery.Container.Children[id] as PicGalleryItem;
-            ConfigureWindows.GetMainWindow.MainImage.Source = z.ThumbImage.Source;
+            var galleryItem = GetPicGallery.Container.Children[id] as PicGalleryItem;
+            ConfigureWindows.GetMainWindow.MainImage.Source = galleryItem.ThumbImage.Source;
         });
 
         Border? border = null;
         Image? image = null;
 
-        var size = ImageSizeFunctions.GetImageSize(Pics[id]);
-        if (size.HasValue)
+        var imageSize = ImageSizeFunctions.GetImageSize(Pics[id]);
+        if (imageSize.HasValue)
         {
             GalleryFunctions.IsGalleryOpen = false;
             await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Send, () =>
             {
                 SetTitle.SetLoadingString();
-                FitImage(size.Value.Width, size.Value.Height);
+                FitImage(imageSize.Value.Width, imageSize.Value.Height);
             });
         }
 
-        var from = GalleryNavigation.PicGalleryItemSize;
-        var to = new[] { XWidth, XHeight };
+        var fromSize = GalleryNavigation.PicGalleryItemSize;
+        var toSize = new[] { XWidth, XHeight };
         var acceleration = 0.2;
         var deceleration = 0.4;
         var duration = TimeSpan.FromSeconds(.3);
 
-        var da = new DoubleAnimation
+        var widthAnimation = new DoubleAnimation
         {
-            From = from,
-            To = to[0],
+            From = fromSize,
+            To = toSize[0],
             Duration = duration,
             AccelerationRatio = acceleration,
             DecelerationRatio = deceleration,
             FillBehavior = FillBehavior.Stop
         };
 
-        var da0 = new DoubleAnimation
+        var heightAnimation = new DoubleAnimation
         {
-            From = from,
-            To = to[1],
+            From = fromSize,
+            To = toSize[1],
             Duration = duration,
             AccelerationRatio = acceleration,
             DecelerationRatio = deceleration,
             FillBehavior = FillBehavior.Stop
         };
 
-        da.Completed += async delegate
+        widthAnimation.Completed += async delegate
         {
             await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, () =>
             {
@@ -117,7 +117,7 @@ internal static class GalleryClick
             }
             else
             {
-                var da3 = new DoubleAnimation
+                var opacityAnimation = new DoubleAnimation
                 {
                     From = 1,
                     To = 0,
@@ -126,17 +126,18 @@ internal static class GalleryClick
                     DecelerationRatio = deceleration,
                     FillBehavior = FillBehavior.Stop
                 };
-                GetPicGallery.Container.BeginAnimation(UIElement.OpacityProperty, da3);
+                GetPicGallery.Container.BeginAnimation(UIElement.OpacityProperty, opacityAnimation);
             }
 
             GetPicGallery.x2.Visibility = Visibility.Hidden;
             GetPicGallery.grid.Children.Add(border);
 
-            border.BeginAnimation(FrameworkElement.WidthProperty, da);
-            border.BeginAnimation(FrameworkElement.HeightProperty, da0);
+            border.BeginAnimation(FrameworkElement.WidthProperty, widthAnimation);
+            border.BeginAnimation(FrameworkElement.HeightProperty, heightAnimation);
         }, DispatcherPriority.Send);
     }
 
+
     private static async Task ItemClickAsync(int id)
     {
         await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>

+ 2 - 2
PicView/SystemIntegration/LockScreenImage.cs

@@ -90,8 +90,8 @@ public static class LockScreenHelper
             var storageFolder = await StorageFolder.GetFolderFromPathAsync(folderPath);
             var imageFile = await storageFolder.GetFileAsync(fileName);
 
-            using var stream = await imageFile.OpenAsync(FileAccessMode.Read).AsTask().ConfigureAwait(false);
-            await LockScreen.SetImageStreamAsync(stream).AsTask().ConfigureAwait(false);
+            using var stream = await imageFile.OpenAsync(FileAccessMode.Read);
+            await LockScreen.SetImageStreamAsync(stream);
         }
         catch (Exception ex)
         {

+ 0 - 5
PicView/SystemIntegration/Wallpaper.cs

@@ -25,13 +25,8 @@ public static class Wallpaper // Taken from a Microsoft sample...
         Fill
     }
 
-    /// <summary>
-    /// NOT thread safe!
-    /// </summary>
-    /// <param name="style"></param>
     internal static async Task SetWallpaperAsync(WallpaperStyle style)
     {
-        // TODO fix wallpaper setting incorrect title
         var url = string.Empty;
         await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
         {

+ 1 - 3
PicView/UILogic/TransformImage/Zoom.cs

@@ -343,9 +343,9 @@ internal static class ZoomLogic
             FillBehavior = FillBehavior.Stop
         };
 
+        // Set intended values after animations
         scaleAnim.Completed += delegate
         {
-            // Hack it to keep the intended value
             _scaleTransform.ScaleX = _scaleTransform.ScaleY = zoomValue;
         };
 
@@ -357,7 +357,6 @@ internal static class ZoomLogic
 
         translateAnimX.Completed += delegate
         {
-            // Hack it to keep the intended value
             _translateTransform.X = newTranslateValueX;
         };
 
@@ -369,7 +368,6 @@ internal static class ZoomLogic
 
         translateAnimY.Completed += delegate
         {
-            // Hack it to keep the intended value
             _translateTransform.Y = newTranslateValueY;
         };