diff --git a/sources/tools/Stride.TextureConverter.Wrappers/DxtWrapper/dxt_wrapper.cpp b/sources/tools/Stride.TextureConverter.Wrappers/DxtWrapper/dxt_wrapper.cpp index 8914e303b9..a584e326b5 100644 --- a/sources/tools/Stride.TextureConverter.Wrappers/DxtWrapper/dxt_wrapper.cpp +++ b/sources/tools/Stride.TextureConverter.Wrappers/DxtWrapper/dxt_wrapper.cpp @@ -109,6 +109,11 @@ HRESULT dxtLoadTGAFile( const char* szFile, DirectX::TexMetadata* metadata, Dire return result; } +HRESULT dxtLoadWICFile(LPCWSTR szFile, int flags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image) +{ + return DirectX::LoadFromWICFile(szFile, flags, metadata, image); +} + HRESULT dxtSaveToDDSFile( const DirectX::Image& image, DirectX::DDS_FLAGS flags, const char* szFile ) { const wchar_t* filePath = narrowToWideString(szFile); diff --git a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs index d5fbf15827..74df7fda73 100644 --- a/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs +++ b/sources/tools/Stride.TextureConverter/Backend/TexLibraries/DxtTexLib.cs @@ -44,7 +44,20 @@ internal class DxtTexLib : ITexLibrary { private static Logger Log = GlobalLogger.GetLogger("DxtTexLib"); - private static HashSet SupportedExtensions = new(StringComparer.InvariantCultureIgnoreCase) + private static HashSet SupportedExtensionsWindows = new(StringComparer.InvariantCultureIgnoreCase) + { + ".dds", + ".bmp", + ".tga", + ".jpg", + ".jpeg", + ".jpe", + ".png", + ".tiff", + ".tif", + }; + + private static HashSet SupportedExtensionsNonWindows = new(StringComparer.InvariantCultureIgnoreCase) { ".dds", ".tga", @@ -125,7 +138,7 @@ public bool CanHandleRequest(PixelFormat format, IRequest request) { case RequestType.Loading: LoadingRequest loader = (LoadingRequest)request; - return loader.Mode==LoadingRequest.LoadingMode.FilePath && SupportedExtensions.Contains(Path.GetExtension(loader.FilePath)); + return loader.Mode==LoadingRequest.LoadingMode.FilePath && IsSupportedExtension(Path.GetExtension(loader.FilePath)); case RequestType.Compressing: CompressingRequest compress = (CompressingRequest)request; @@ -158,6 +171,18 @@ public bool CanHandleRequest(PixelFormat format, IRequest request) } } + private bool IsSupportedExtension(string fileExtension) + { + if (OperatingSystem.IsWindows()) + { + return SupportedExtensionsWindows.Contains(fileExtension); + } + else + { + return SupportedExtensionsNonWindows.Contains(fileExtension); + } + } + public void Execute(TexImage image, IRequest request) { DxtTextureLibraryData libraryData = image.LibraryData.TryGetValue(this, out var libData) ? (DxtTextureLibraryData)libData : null; @@ -222,7 +247,15 @@ private void Load(TexImage image, LoadingRequest loader) { hr = Utilities.LoadTGAFile(loader.FilePath, out libraryData.Metadata, libraryData.Image); } - + else if (OperatingSystem.IsWindows()) + { + hr = Utilities.LoadWICFile(loader.FilePath, WIC_FLAGS.WIC_FLAGS_NONE, out libraryData.Metadata, libraryData.Image); + } + else + { + hr = (HRESULT)(-1); + } + if (hr != HRESULT.S_OK) { Log.Error("Loading dds file " + loader.FilePath + " failed: " + hr); diff --git a/sources/tools/Stride.TextureConverter/Backend/Wrappers/DxtNetWrapper.cs b/sources/tools/Stride.TextureConverter/Backend/Wrappers/DxtNetWrapper.cs index 2354028fd4..49b5427a38 100644 --- a/sources/tools/Stride.TextureConverter/Backend/Wrappers/DxtNetWrapper.cs +++ b/sources/tools/Stride.TextureConverter/Backend/Wrappers/DxtNetWrapper.cs @@ -521,6 +521,9 @@ internal class Utilities [DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] private extern static uint dxtLoadTGAFile(string filePath, out TexMetadata metadata, IntPtr image); + [DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] + private extern static uint dxtLoadWICFile(String filePath, WIC_FLAGS flags, out TexMetadata metadata, IntPtr image); + [DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] private extern static bool dxtIsCompressed(DXGI_FORMAT fmt); @@ -584,6 +587,11 @@ public static HRESULT LoadTGAFile(string filePath, out TexMetadata metadata, Scr return HandleHRESULT(dxtLoadTGAFile(filePath, out metadata, image.ptr)); } + public static HRESULT LoadWICFile(String filePath, WIC_FLAGS flags, out TexMetadata metadata, ScratchImage image) + { + return HandleHRESULT(dxtLoadWICFile(filePath, flags, out metadata, image.ptr)); + } + public static HRESULT SaveToDDSFile(ref DxtImage dxtImage, DDS_FLAGS flags, string szFile) { return HandleHRESULT(dxtSaveToDDSFile(ref dxtImage, flags, szFile));