From 236af4e9ab43b396e0d4aef0cd6389f9c3919dd2 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Mon, 18 Oct 2021 11:48:10 +1300 Subject: [PATCH] Refactored App and Connection Page, and fixed a few issues --- PDGServer_WPF/App.xaml.cs | 31 ++-- PDGServer_WPF/ConnectionPage.xaml | 2 + PDGServer_WPF/ConnectionPage.xaml.cs | 220 +++++++++++++++++---------- 3 files changed, 156 insertions(+), 97 deletions(-) diff --git a/PDGServer_WPF/App.xaml.cs b/PDGServer_WPF/App.xaml.cs index 3b427e4..06ee999 100644 --- a/PDGServer_WPF/App.xaml.cs +++ b/PDGServer_WPF/App.xaml.cs @@ -26,6 +26,11 @@ namespace RBG_Server protected static readonly SolidColorBrush BLUE_BRUSH = new(Color.FromRgb(0, 0, 255)); protected static readonly SolidColorBrush GREEN_BRUSH = new(Color.FromRgb(0, 255, 0)); + public const string MIP_LOW = "_mip_low"; + public const string MIP_MEDIUM = "_mip_med"; + public const string MIP_HIGH = "_mip_high"; + public const string MIP_RAW = "_mip_raw"; + /// /// Loads the specified files from disk, creating mip maps as appropriate /// @@ -74,26 +79,26 @@ namespace RBG_Server { double scaleRate = 32 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(decoder.Thumbnail, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_low" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_LOW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } else { double scaleRate = 32 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(frames[0], scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_low" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_LOW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } // The remaining mips are animated if (width >= 128 || height >= 128) { double scaleRate = 128 / (double)Math.Max(height, width); MemoryStream ms = ScaleAnimatedImage(frames, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_med" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_MEDIUM + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 512 || height >= 512) { double scaleRate = 512 / (double)Math.Max(height, width); MemoryStream ms = ScaleAnimatedImage(frames, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_high" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_HIGH + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 512 || height >= 512) { @@ -105,7 +110,7 @@ namespace RBG_Server } MemoryStream ms = new(); encoder.Save(ms); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_raw" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_RAW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } } @@ -132,25 +137,25 @@ namespace RBG_Server { double scaleRate = 32 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_low" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_LOW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 128 || height >= 128) { double scaleRate = 128 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_med" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_MEDIUM + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 512 || height >= 512) { double scaleRate = 512 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_high" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_HIGH + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 512 || height >= 512) { MemoryStream ms = new(); source.CopyTo(ms); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_raw" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_RAW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } } else @@ -163,25 +168,25 @@ namespace RBG_Server { double scaleRate = 128 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_low" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_LOW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 512 || height >= 512) { double scaleRate = 512 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_med" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_MEDIUM + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 2048 || height >= 2048) { double scaleRate = 2048 / (double)Math.Max(height, width); MemoryStream ms = ScaleImage(bitmapImage, scaleRate); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_high" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_HIGH + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } if (width >= 2048 || height >= 2048) { MemoryStream ms = new(); source.CopyTo(ms); - _ = communicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + "_mip_raw" + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); + _ = GameCommunicationHandler.ImageCollection.TryAdd(Path.GetFileNameWithoutExtension(path) + MIP_RAW + Path.GetExtension(path), new CachedByteArray(ms.ToArray())); } } } diff --git a/PDGServer_WPF/ConnectionPage.xaml b/PDGServer_WPF/ConnectionPage.xaml index 1dda3c7..f2d28f3 100644 --- a/PDGServer_WPF/ConnectionPage.xaml +++ b/PDGServer_WPF/ConnectionPage.xaml @@ -61,6 +61,8 @@ + +