From 69792b32622ef7726967a894ef8794cfcdef406e Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 9 Jun 2025 17:22:31 +0800 Subject: [PATCH] refactor: do not upscale images Signed-off-by: leo --- src/Views/ImageContainer.cs | 20 +++----------------- src/Views/ImageDiffView.axaml | 16 ++++++++-------- src/Views/RevisionFileContentViewer.axaml | 2 +- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/Views/ImageContainer.cs b/src/Views/ImageContainer.cs index b62746ed..2c37d12a 100644 --- a/src/Views/ImageContainer.cs +++ b/src/Views/ImageContainer.cs @@ -86,26 +86,12 @@ namespace SourceGit.Views var imageSize = image.Size; var scaleW = availableSize.Width / imageSize.Width; var scaleH = availableSize.Height / imageSize.Height; - var scale = Math.Min(scaleW, scaleH); + var scale = Math.Min(1, Math.Min(scaleW, scaleH)); return new Size(scale * imageSize.Width, scale * imageSize.Height); } return availableSize; } - - protected override Size ArrangeOverride(Size finalSize) - { - if (Image is { } image) - { - var imageSize = image.Size; - var scaleW = finalSize.Width / imageSize.Width; - var scaleH = finalSize.Height / imageSize.Height; - var scale = Math.Min(scaleW, scaleH); - return new Size(scale * imageSize.Width, scale * imageSize.Height); - } - - return base.ArrangeOverride(finalSize); - } } public class ImageSwipeControl : ImageContainer @@ -243,7 +229,7 @@ namespace SourceGit.Views { var sw = available.Width / img.Width; var sh = available.Height / img.Height; - var scale = Math.Min(sw, sh); + var scale = Math.Min(1, Math.Min(sw, sh)); return new Size(scale * img.Width, scale * img.Height); } @@ -348,7 +334,7 @@ namespace SourceGit.Views { var sw = available.Width / img.Width; var sh = available.Height / img.Height; - var scale = Math.Min(sw, sh); + var scale = Math.Min(1, Math.Min(sw, sh)); return new Size(scale * img.Width, scale * img.Height); } diff --git a/src/Views/ImageDiffView.axaml b/src/Views/ImageDiffView.axaml index d0b79f57..54a20628 100644 --- a/src/Views/ImageDiffView.axaml +++ b/src/Views/ImageDiffView.axaml @@ -32,8 +32,8 @@ - - + + @@ -52,8 +52,8 @@ - - + + @@ -87,8 +87,8 @@ - - + + - - + + - +