From c4c4e9163efef0738c99db1eeeedb575fb8d1c69 Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 1 Jan 2025 16:33:35 +0100 Subject: [PATCH] Add option to change image aliasing --- .../ViewModels/ViewModelBase.cs | 14 ++++++++++ .../Views/GeneralSettingsView.axaml.cs | 4 --- .../Views/ImageSettingsView.axaml | 21 +++++++++++++++ .../Views/ImageSettingsView.axaml.cs | 27 +++++++++++++++++++ src/PicView.Avalonia/Views/ImageViewer.axaml | 1 - .../Views/ImageViewer.axaml.cs | 16 +++++++++++ 6 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/PicView.Avalonia/ViewModels/ViewModelBase.cs b/src/PicView.Avalonia/ViewModels/ViewModelBase.cs index bd1c2ddb..802cfd4d 100644 --- a/src/PicView.Avalonia/ViewModels/ViewModelBase.cs +++ b/src/PicView.Avalonia/ViewModels/ViewModelBase.cs @@ -256,10 +256,24 @@ public void UpdateLanguage() WidthAndHeight = TranslationHelper.Translation.WidthAndHeight; CloseWindowPrompt = TranslationHelper.Translation.CloseWindowPrompt; ShowConfirmationOnEsc = TranslationHelper.Translation.ShowConfirmationOnEsc; + ImageAliasing = TranslationHelper.Translation.ImageAliasing; + HighQuality = TranslationHelper.Translation.HighQuality; } #region Strings + public string? HighQuality + { + get; + set => this.RaiseAndSetIfChanged(ref field, value); + } + + public string? ImageAliasing + { + get; + set => this.RaiseAndSetIfChanged(ref field, value); + } + public string? CloseWindowPrompt { get; diff --git a/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs b/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs index c9b36cac..e8b8c164 100644 --- a/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs +++ b/src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs @@ -10,8 +10,6 @@ public GeneralSettingsView() InitializeComponent(); Loaded += delegate { - - ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 1 : 0; ApplicationStartupBox.SelectionChanged += async delegate @@ -30,8 +28,6 @@ public GeneralSettingsView() ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 0 : 1; } }; - - }; } } \ No newline at end of file diff --git a/src/PicView.Avalonia/Views/ImageSettingsView.axaml b/src/PicView.Avalonia/Views/ImageSettingsView.axaml index 631a893c..30508692 100644 --- a/src/PicView.Avalonia/Views/ImageSettingsView.axaml +++ b/src/PicView.Avalonia/Views/ImageSettingsView.axaml @@ -74,5 +74,26 @@ Mode=OneWay}" /> + + + + + + diff --git a/src/PicView.Avalonia/Views/ImageSettingsView.axaml.cs b/src/PicView.Avalonia/Views/ImageSettingsView.axaml.cs index d80d36ed..9f1b4ebd 100644 --- a/src/PicView.Avalonia/Views/ImageSettingsView.axaml.cs +++ b/src/PicView.Avalonia/Views/ImageSettingsView.axaml.cs @@ -1,4 +1,6 @@ using Avalonia.Controls; +using PicView.Avalonia.ViewModels; +using PicView.Core.Config; namespace PicView.Avalonia.Views; public partial class ImageSettingsView : UserControl @@ -6,5 +8,30 @@ public partial class ImageSettingsView : UserControl public ImageSettingsView() { InitializeComponent(); + Loaded += delegate + { + ImageAliasingBox.SelectedIndex = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor ? 1 : 0; + + ImageAliasingBox.SelectionChanged += async delegate + { + if (ImageAliasingBox.SelectedIndex == -1) + { + return; + } + SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor = ImageAliasingBox.SelectedIndex == 1; + if (DataContext is MainViewModel vm) + { + vm.ImageViewer.TriggerScalingModeUpdate(true); + } + await SettingsHelper.SaveSettingsAsync(); + }; + ImageAliasingBox.DropDownOpened += delegate + { + if (ImageAliasingBox.SelectedIndex == -1) + { + ImageAliasingBox.SelectedIndex = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor ? 0 : 1; + } + }; + }; } } diff --git a/src/PicView.Avalonia/Views/ImageViewer.axaml b/src/PicView.Avalonia/Views/ImageViewer.axaml index 71f4d1a1..5b76349e 100644 --- a/src/PicView.Avalonia/Views/ImageViewer.axaml +++ b/src/PicView.Avalonia/Views/ImageViewer.axaml @@ -36,7 +36,6 @@ PointerMoved="MainImage_OnPointerMoved" PointerPressed="MainImage_OnPointerPressed" PointerReleased="MainImage_OnPointerReleased" - RenderOptions.BitmapInterpolationMode="HighQuality" SecondaryImageWidth="{CompiledBinding SecondaryImageWidth, Mode=OneWay}" SecondarySource="{CompiledBinding SecondaryImageSource, diff --git a/src/PicView.Avalonia/Views/ImageViewer.axaml.cs b/src/PicView.Avalonia/Views/ImageViewer.axaml.cs index b41965ab..1ed5b4b0 100644 --- a/src/PicView.Avalonia/Views/ImageViewer.axaml.cs +++ b/src/PicView.Avalonia/Views/ImageViewer.axaml.cs @@ -5,6 +5,7 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; +using Avalonia.Media.Imaging; using Avalonia.Threading; using PicView.Avalonia.Navigation; using PicView.Avalonia.UI; @@ -33,6 +34,7 @@ public partial class ImageViewer : UserControl public ImageViewer() { InitializeComponent(); + TriggerScalingModeUpdate(false); AddHandler(PointerWheelChangedEvent, PreviewOnPointerWheelChanged, RoutingStrategies.Tunnel); AddHandler(Gestures.PointerTouchPadGestureMagnifyEvent, TouchMagnifyEvent, RoutingStrategies.Bubble); @@ -45,6 +47,19 @@ public ImageViewer() }; }; } + + public void TriggerScalingModeUpdate(bool invalidate) + { + var scalingMode = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor + ? BitmapInterpolationMode.LowQuality + : BitmapInterpolationMode.HighQuality; + + RenderOptions.SetBitmapInterpolationMode(MainImage,scalingMode); + if (invalidate) + { + MainImage.InvalidateVisual(); + } + } private void TouchMagnifyEvent(object? sender, PointerDeltaEventArgs e) { @@ -256,6 +271,7 @@ public void ZoomTo(Point point, bool isZoomIn) currentZoom += zoomSpeed; currentZoom = Math.Max(0.09, currentZoom); // Fix for zooming out too much + TriggerScalingModeUpdate(false); if (SettingsHelper.Settings.Zoom.AvoidZoomingOut && currentZoom < 1.0) { ResetZoom(true);