Skip to content

Commit

Permalink
Experiments (#469, #495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Sep 7, 2023
1 parent c84ab55 commit 7ce8a22
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
8 changes: 5 additions & 3 deletions projects/GKv3/GEDKeeper3/GKUI/Components/TreeChartBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions projects/GKv3/GKComponents/GKUI/Components/ScrollablePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 1 addition & 12 deletions projects/GKv3/GKComponents/GKUI/Platform/EtoGfxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using BSLib;
using Eto.Drawing;
using Eto.Forms;
using ExifLibrary;
using GKCore;
using GKCore.Design.Graphics;
using GKUI.Components;
Expand All @@ -42,17 +41,7 @@ public EtoGfxProvider()

public Stream CheckOrientation(Stream inputStream)
{
Stream transformStream;

var file = ImageFile.FromStream(inputStream);
var orientProp = file.Properties.Get<ExifEnumProperty<ExifLibrary.Orientation>>(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;
}
Expand Down
30 changes: 29 additions & 1 deletion projects/GKv3/GKComponents/GKUI/Platform/ImageProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using System.IO;
using ExifLibrary;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.PixelFormats;
Expand All @@ -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<ExifEnumProperty<Orientation>>(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<Bgr565>(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);
}
Expand Down

0 comments on commit 7ce8a22

Please sign in to comment.