From 7ce8a227853b9d59ce568460b469645d2b350924 Mon Sep 17 00:00:00 2001 From: "Serg V. Zhdanovskih (Norseman)" Date: Thu, 7 Sep 2023 10:43:43 +0300 Subject: [PATCH] Experiments (#469, #495) --- .../GKUI/Components/TreeChartBox.cs | 8 +++-- .../GKUI/Components/ScrollablePanel.cs | 2 ++ .../GKUI/Platform/EtoGfxProvider.cs | 13 +------- .../GKUI/Platform/ImageProcess.cs | 30 ++++++++++++++++++- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/projects/GKv3/GEDKeeper3/GKUI/Components/TreeChartBox.cs b/projects/GKv3/GEDKeeper3/GKUI/Components/TreeChartBox.cs index 9353e51be..6fc5384f1 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Components/TreeChartBox.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Components/TreeChartBox.cs @@ -572,13 +572,15 @@ protected override void OnMouseDoubleClick(MouseEventArgs e) protected override void OnMouseWheel(MouseEventArgs e) { + //Console.WriteLine("TreeChartBox.OnMouseWheel()"); + if (e.Modifiers == Keys.Control) { float newScale = (e.Delta.Height > 0) ? fModel.Scale + 0.05f : fModel.Scale - 0.05f; + //Console.WriteLine(string.Format("{0} - {1} - {2}", e.Delta.Height, fModel.Scale, newScale)); SetScale(newScale); - } - e.Handled = true; - base.OnMouseWheel(e); + e.Handled = true; + } else base.OnMouseWheel(e); } private MouseAction GetMouseAction(MouseEventArgs e, MouseEvent mouseEvent, out TreeChartPerson person) diff --git a/projects/GKv3/GKComponents/GKUI/Components/ScrollablePanel.cs b/projects/GKv3/GKComponents/GKUI/Components/ScrollablePanel.cs index 42fd8638a..cce98454a 100644 --- a/projects/GKv3/GKComponents/GKUI/Components/ScrollablePanel.cs +++ b/projects/GKv3/GKComponents/GKUI/Components/ScrollablePanel.cs @@ -244,6 +244,8 @@ protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseWheel(MouseEventArgs e) { + //Console.WriteLine("ScrollablePanel.OnMouseWheel()"); + int delta = -(int)(e.Delta.Height * 120.0f); if (Keys.None == e.Modifiers) { diff --git a/projects/GKv3/GKComponents/GKUI/Platform/EtoGfxProvider.cs b/projects/GKv3/GKComponents/GKUI/Platform/EtoGfxProvider.cs index 589aba210..4c1f7fcb6 100644 --- a/projects/GKv3/GKComponents/GKUI/Platform/EtoGfxProvider.cs +++ b/projects/GKv3/GKComponents/GKUI/Platform/EtoGfxProvider.cs @@ -23,7 +23,6 @@ using BSLib; using Eto.Drawing; using Eto.Forms; -using ExifLibrary; using GKCore; using GKCore.Design.Graphics; using GKUI.Components; @@ -42,17 +41,7 @@ public EtoGfxProvider() public Stream CheckOrientation(Stream inputStream) { - Stream transformStream; - - var file = ImageFile.FromStream(inputStream); - var orientProp = file.Properties.Get>(ExifTag.Orientation); - if (orientProp != null && orientProp.Value != ExifLibrary.Orientation.Normal) { - inputStream.Seek(0, SeekOrigin.Begin); - transformStream = ImageProcess.AutoOrient(inputStream); - } else { - transformStream = inputStream; - } - + Stream transformStream = ImageProcess.IsNeedOrient(inputStream) ? ImageProcess.AutoOrient(inputStream) : inputStream; transformStream.Seek(0, SeekOrigin.Begin); return transformStream; } diff --git a/projects/GKv3/GKComponents/GKUI/Platform/ImageProcess.cs b/projects/GKv3/GKComponents/GKUI/Platform/ImageProcess.cs index aa04e0bb6..efb2c8b06 100644 --- a/projects/GKv3/GKComponents/GKUI/Platform/ImageProcess.cs +++ b/projects/GKv3/GKComponents/GKUI/Platform/ImageProcess.cs @@ -19,6 +19,7 @@ */ using System.IO; +using ExifLibrary; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.PixelFormats; @@ -28,11 +29,38 @@ namespace GKUI.Platform { public static class ImageProcess { + public static bool IsNeedOrient(Stream inputStream) + { + try { + try { + var file = ImageFile.FromStream(inputStream); + var orientProp = file.Properties.Get>(ExifTag.Orientation); + return (orientProp != null && orientProp.Value != Orientation.Normal); + } finally { + inputStream.Seek(0, SeekOrigin.Begin); + } + } catch { + return false; + } + } + public static Stream AutoOrient(Stream inputStream) { var outputStream = new MemoryStream(); using (var image = Image.Load(inputStream)) { - image.Mutate(x => x.AutoOrient()); + /*var scrSize = Screen.PrimaryScreen.Bounds.Size; + var resizeRatio = GfxHelper.ZoomToFit(image.Width, image.Height, scrSize.Width, scrSize.Height); + int targetWidth = (int)Math.Round(image.Width * resizeRatio); + int targetHeight = (int)Math.Round(image.Height * resizeRatio);*/ + + /*var targetDPI = Screen.PrimaryScreen.DPI; + double currentDPI = image.Metadata.HorizontalResolution; + double resizeRatio = targetDPI / currentDPI; + if (resizeRatio < 0.1) { resizeRatio *= 10.0f; } + int targetWidth = (int)Math.Round(image.Width * resizeRatio); + int targetHeight = (int)Math.Round(image.Height * resizeRatio);*/ + + image.Mutate(x => x./*Resize(targetWidth, targetHeight).*/AutoOrient()); var encoder = new BmpEncoder() { BitsPerPixel = BmpBitsPerPixel.Pixel16 }; image.SaveAsBmp(outputStream, encoder); }