Jelajahi Sumber

Ignore exif rotation value for heic #207

Ruben 4 bulan lalu
induk
melakukan
48d1aa3981

+ 7 - 7
src/PicView.Avalonia/ImageHandling/GetImageModel.cs

@@ -46,6 +46,7 @@ public static class GetImageModel
 
             // Extract EXIF orientation early
             imageModel.EXIFOrientation = EXIFHelper.GetImageOrientation(magickImage);
+            imageModel.Format = magickImage.Format;
 
             // Process the image based on extension
             if (ExtensionHandlers.TryGetValue(ext, out var handler))
@@ -98,13 +99,12 @@ public static class GetImageModel
     {
         public abstract Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel);
 
-        protected static void SetBitmapModel(Bitmap bitmap, FileInfo fileInfo, ImageModel imageModel, ImageType imageType = ImageType.Bitmap)
+        protected static void SetBitmapModel(Bitmap bitmap, ImageModel imageModel, ImageType imageType = ImageType.Bitmap)
         {
             imageModel.Image = bitmap;
             imageModel.PixelWidth = bitmap?.PixelSize.Width ?? 0;
             imageModel.PixelHeight = bitmap?.PixelSize.Height ?? 0;
             imageModel.ImageType = imageType;
-            imageModel.EXIFOrientation = EXIFHelper.GetImageOrientation(fileInfo);
         }
     }
 
@@ -114,7 +114,7 @@ public static class GetImageModel
         public override async Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel)
         {
             var bitmap = await GetImage.GetStandardBitmapAsync(fileInfo).ConfigureAwait(false);
-            SetBitmapModel(bitmap, fileInfo, imageModel);
+            SetBitmapModel(bitmap, imageModel);
         }
     }
 
@@ -124,7 +124,7 @@ public static class GetImageModel
         public override async Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel)
         {
             var bitmap = await GetImage.GetStandardBitmapAsync(fileInfo).ConfigureAwait(false);
-            SetBitmapModel(bitmap, fileInfo, imageModel, 
+            SetBitmapModel(bitmap, imageModel, 
                 ImageAnalyzer.IsAnimated(fileInfo) ? ImageType.AnimatedWebp : ImageType.Bitmap);
         }
     }
@@ -135,7 +135,7 @@ public static class GetImageModel
         public override async Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel)
         {
             var bitmap = await GetImage.GetStandardBitmapAsync(fileInfo).ConfigureAwait(false);
-            SetBitmapModel(bitmap, fileInfo, imageModel, 
+            SetBitmapModel(bitmap, imageModel, 
                 ImageAnalyzer.IsAnimated(fileInfo) ? ImageType.AnimatedGif : ImageType.Bitmap);
         }
     }
@@ -163,7 +163,7 @@ public static class GetImageModel
         public override async Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel)
         {
             var bitmap = await GetImage.GetBase64ImageAsync(fileInfo).ConfigureAwait(false);
-            SetBitmapModel(bitmap, fileInfo, imageModel);
+            SetBitmapModel(bitmap, imageModel);
         }
     }
 
@@ -173,7 +173,7 @@ public static class GetImageModel
         public override async Task ProcessImageAsync(FileInfo fileInfo, ImageModel imageModel)
         {
             var bitmap = await GetImage.GetDefaultBitmapAsync(fileInfo).ConfigureAwait(false);
-            SetBitmapModel(bitmap, fileInfo, imageModel);
+            SetBitmapModel(bitmap, imageModel);
         }
     }
 

+ 4 - 1
src/PicView.Avalonia/ImageHandling/ImageModel.cs

@@ -1,4 +1,5 @@
-using PicView.Core.ImageDecoding;
+using ImageMagick;
+using PicView.Core.ImageDecoding;
 
 namespace PicView.Avalonia.ImageHandling;
 
@@ -10,6 +11,8 @@ public class ImageModel
     public int PixelHeight { get; set; }
     public EXIFHelper.EXIFOrientation? EXIFOrientation { get; set; }
     public ImageType ImageType { get; set; }
+    
+    public MagickFormat? Format { get; set; }
 
     public double Rotation
     {

+ 3 - 2
src/PicView.Avalonia/Navigation/UpdateImage.cs

@@ -76,7 +76,8 @@ public static class UpdateImage
                 return;
             }
 
-            vm.ImageViewer.SetTransform(preLoadValue.ImageModel.EXIFOrientation);
+            vm.ImageViewer.SetTransform(preLoadValue.ImageModel.EXIFOrientation, preLoadValue.ImageModel.Format);
+
             if (Settings.ImageScaling.ShowImageSideBySide && nextPreloadValue is { ImageModel: not null })
             {
                 vm.PicViewer.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
@@ -166,7 +167,7 @@ public static class UpdateImage
         {
             WindowResizing.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
                 nextPreloadValue?.ImageModel?.PixelWidth ?? 0, nextPreloadValue?.ImageModel?.PixelHeight ?? 0,
-                preLoadValue.ImageModel.Rotation, vm);
+                vm.RotationAngle, vm);
         }
 
     }

+ 2 - 2
src/PicView.Avalonia/StartUp/QuickLoad.cs

@@ -112,6 +112,7 @@ public static class QuickLoad
         {
             await Dispatcher.UIThread.InvokeAsync(() =>
             {
+                vm.ImageViewer.SetTransform(EXIFHelper.GetImageOrientation(magickImage), magickImage.Format);
                 WindowResizing.SetSize(magickImage.Width, magickImage.Height, vm);
                 WindowFunctions.CenterWindowOnScreen();
             }, DispatcherPriority.Send);
@@ -166,7 +167,7 @@ public static class QuickLoad
         {
             vm.ImageViewer.MainImage.InitialAnimatedSource = fileInfo.FullName;
         }
-
+        
         vm.PicViewer.ImageSource = imageModel.Image;
         vm.PicViewer.ImageType = imageModel.ImageType;
         vm.ZoomValue = 1;
@@ -193,7 +194,6 @@ public static class QuickLoad
 
         await Dispatcher.UIThread.InvokeAsync(() =>
         {
-            vm.ImageViewer.SetTransform(imageModel.EXIFOrientation, false);
             if (is1To1)
             {
                 var size = WindowResizing.GetSize(imageModel.PixelWidth, imageModel.PixelHeight,

+ 11 - 1
src/PicView.Avalonia/Views/ImageViewer.axaml.cs

@@ -6,6 +6,7 @@ using Avalonia.Interactivity;
 using Avalonia.Media;
 using Avalonia.Media.Imaging;
 using Avalonia.Threading;
+using ImageMagick;
 using PicView.Avalonia.ImageTransformations;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.ViewModels;
@@ -324,7 +325,7 @@ public partial class ImageViewer : UserControl
         }
     }
 
-    public void SetTransform(EXIFHelper.EXIFOrientation? orientation, bool reset = true)
+    public void SetTransform(EXIFHelper.EXIFOrientation? orientation, MagickFormat? format, bool reset = true)
     {
         if (Dispatcher.UIThread.CheckAccess())
         {
@@ -343,6 +344,15 @@ public partial class ImageViewer : UserControl
                 ImageScrollViewer.ScrollToHome();
             }
 
+            if (format is MagickFormat.Heic or MagickFormat.Heif)
+            {
+                if (reset)
+                {
+                    SetTransform(1,0);
+                }
+                return;
+            }
+            
             switch (orientation)
             {
                 case null:

+ 1 - 1
src/PicView.Avalonia/WindowBehavior/WindowResizing.cs

@@ -80,7 +80,7 @@ public static class WindowResizing
     }
     
     public static void SetSize(double width, double height, MainViewModel vm) 
-        => SetSize(width, height, 0, 0, 0, vm);
+        => SetSize(width, height, 0, 0, vm.RotationAngle, vm);
 
     public static void SetSize(double width, double height, double secondWidth, double secondHeight, double rotation,
         MainViewModel vm)