mirror of
https://github.com/MathiasLui/CSGO-Projects.git
synced 2025-05-06 13:51:18 +00:00
Change DDSImage class to use Pfim instead, that supports DX10 headers
* While testing, one map couldn't be loaded (dz_county) because it had a DX10 header. It's not in the game anymore but change it anyways for more compatibility
This commit is contained in:
parent
b21ea87e7a
commit
f38a3ebef8
2 changed files with 19 additions and 21 deletions
|
@ -11,6 +11,8 @@ using System.Text;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Management;
|
||||
using Pfim;
|
||||
using System.Drawing;
|
||||
|
||||
namespace SteamShared
|
||||
{
|
||||
|
@ -228,36 +230,31 @@ namespace SteamShared
|
|||
|
||||
// Save map name without prefix
|
||||
map.MapFileName = System.IO.Path.GetFileNameWithoutExtension(file).Split('_').Last();
|
||||
|
||||
DDSImage image;
|
||||
|
||||
Bitmap image;
|
||||
try
|
||||
{
|
||||
// Read actual radar
|
||||
image = new DDSImage(System.IO.File.ReadAllBytes(map.MapImagePath!));
|
||||
using (var pfimImage = Pfimage.FromFile(map.MapImagePath))
|
||||
{
|
||||
// TODO: Do we need to support more pixel formats?
|
||||
System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
|
||||
|
||||
// If this is still commented out after ages, I'm sorry @FutureMe
|
||||
//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);
|
||||
//}
|
||||
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
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (image.BitmapImage.Width != image.BitmapImage.Height)
|
||||
if (image.Width != image.Height)
|
||||
// We only want square map images, which should normally always be given
|
||||
continue;
|
||||
|
||||
|
@ -265,7 +262,7 @@ namespace SteamShared
|
|||
// 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);
|
||||
map.MapImage = Globals.BitmapToImageSource(image);
|
||||
});
|
||||
|
||||
maps.Add(map);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Pfim" Version="0.11.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
<PackageReference Include="System.Management" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Add table
Reference in a new issue