From 962cfac30a067cb9cfa3f3117d2bbcc033885a4f Mon Sep 17 00:00:00 2001 From: MathiasLui Date: Thu, 23 Jun 2022 11:57:49 +0200 Subject: [PATCH] (draft) Add Pfim image library and non-tested code * We want to be able to load extended DX10 headers and this library might be able to do it, but I can't test it on this machine --- DamageCalculator/DamageCalculator.sln | 8 +++++++- SteamShared/Pfim | 1 + .../SteamShared/SteamShared/CsgoHelper.cs | 19 ++++++++++++++++++- .../SteamShared/SteamShared.csproj | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 160000 SteamShared/Pfim diff --git a/DamageCalculator/DamageCalculator.sln b/DamageCalculator/DamageCalculator.sln index 0f08ba4..690f4d6 100644 --- a/DamageCalculator/DamageCalculator.sln +++ b/DamageCalculator/DamageCalculator.sln @@ -3,10 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.32228.430 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DamageCalculator", "DamageCalculator\DamageCalculator.csproj", "{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageCalculator", "DamageCalculator\DamageCalculator.csproj", "{7A7AE40F-8677-44E3-873A-4AB7C9FCFEB4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamShared", "..\SteamShared\SteamShared\SteamShared\SteamShared.csproj", "{3632D445-DC7D-43FC-AC66-8503F50FCA2A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pfim", "..\SteamShared\Pfim\src\Pfim\Pfim.csproj", "{0EA4ECBB-6036-4936-8ABC-3F8AC154AB93}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU {3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU {3632D445-DC7D-43FC-AC66-8503F50FCA2A}.Release|Any CPU.Build.0 = Release|Any CPU + {0EA4ECBB-6036-4936-8ABC-3F8AC154AB93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EA4ECBB-6036-4936-8ABC-3F8AC154AB93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EA4ECBB-6036-4936-8ABC-3F8AC154AB93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EA4ECBB-6036-4936-8ABC-3F8AC154AB93}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SteamShared/Pfim b/SteamShared/Pfim new file mode 160000 index 0000000..a69286b --- /dev/null +++ b/SteamShared/Pfim @@ -0,0 +1 @@ +Subproject commit a69286bfcfea4abb6b03b2c8685b211cab427136 diff --git a/SteamShared/SteamShared/SteamShared/CsgoHelper.cs b/SteamShared/SteamShared/SteamShared/CsgoHelper.cs index 36775e2..2de26e0 100644 --- a/SteamShared/SteamShared/SteamShared/CsgoHelper.cs +++ b/SteamShared/SteamShared/SteamShared/CsgoHelper.cs @@ -205,7 +205,23 @@ namespace SteamShared try { // Read actual radar - image = new DDSImage(System.IO.File.ReadAllBytes(map.MapImagePath!)); + //image = new DDSImage(System.IO.File.ReadAllBytes(map.MapImagePath!)); + + using (var pfimImage = Pfim.Pfim.FromFile(map.MapImagePath)) + { + // TODO: Do we need to support more pixel formats? + System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb; + + if(pfimImage.Format == Pfim.ImageFormat.Rgba32) + { + format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; + } + + // Maybe pin it so GC doesn't collect it, for now just ignore it + var data = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(pfimImage.Data, 0); + image = new System.Drawing.Bitmap(pfimImage.Width, pfimImage.Height, pfimImage.Stride, format, data); + } + } catch { @@ -217,6 +233,7 @@ namespace SteamShared continue; // Some workaround I found online for some thread error I forgot + // Future self: We probably want to execute it on the thread that owns the image System.Windows.Application.Current.Dispatcher.Invoke((Action)delegate { map.MapImage = Globals.BitmapToImageSource(image.BitmapImage); diff --git a/SteamShared/SteamShared/SteamShared/SteamShared.csproj b/SteamShared/SteamShared/SteamShared/SteamShared.csproj index 0146f25..a45429d 100644 --- a/SteamShared/SteamShared/SteamShared/SteamShared.csproj +++ b/SteamShared/SteamShared/SteamShared/SteamShared.csproj @@ -13,6 +13,9 @@ + + + Never