From af00d970a6a44faeb956d880baf41ab03fbb81c4 Mon Sep 17 00:00:00 2001 From: Ivan Panayotov Date: Mon, 19 Aug 2024 16:29:43 +0300 Subject: [PATCH] Update all --- .../TelltaleTextureTool/App.axaml | 66 +- .../TelltaleTextureTool/Converter.cs | 10 +- .../GUI/ImageAdvancedOptions.cs | 135 + .../TelltaleTextureTool/GUI/ImageBitmap.cs | 36 - .../TelltaleTextureTool/GUI/ImageData.cs | 431 +-- .../GUI/ImageProperties.cs | 23 +- .../GUI/ViewModels/MainViewModel.cs | 195 +- .../GUI/Views/MainView.axaml | 623 ++-- .../GUI/Views/MainView.axaml.cs | 12 +- .../GUI/Views/MainWindow.axaml | 2 +- .../Graphics/DDS/DDS_DirectXTexNet.cs | 1033 ++++--- .../Graphics/DDS/DDS_HELPER.cs | 263 +- .../Graphics/Decoder/BitHelper.cs | 391 --- .../Decoder/Bitmap/ArrayPoolBitmap.cs | 59 - .../Decoder/Bitmap/ArraySegmentBitmap.cs | 44 - .../Graphics/Decoder/Bitmap/IBitmap.cs | 15 - .../Decoder/Bitmap/IDisposableBitmap.cs | 8 - .../Graphics/Decoder/Bitmap/MemoryBitmap.cs | 35 - .../Decoder/Bitmap/MemoryPoolBitmap.cs | 43 - .../Graphics/Decoder/Bitmap/NativeBitmap.cs | 57 - .../Graphics/Decoder/Bitmap/RefBitmap.cs | 50 - .../Decoder/Texture/Coder/L8_UByte.cs | 60 - .../Texture/Coder/RGBA_ATC_Explicit_UByte.cs | 80 - .../Coder/RGBA_ATC_Interpolated_UByte.cs | 80 - .../Texture/Coder/RGBA_BC1_PS4_UByte.cs | 102 - .../Texture/Coder/RGBA_ETC2_EAC_UByte.cs | 69 - .../Coder/RGBA_ETC2_Punchthrough_UByte.cs | 69 - .../Texture/Coder/RGBA_PVRTCII_2BPP_UByte.cs | 44 - .../Texture/Coder/RGBA_PVRTCII_4BPP_UByte.cs | 36 - .../Texture/Coder/RGBA_PVRTCI_2BPP_UByte.cs | 45 - .../Texture/Coder/RGBA_PVRTCI_4BPP_UByte.cs | 45 - .../Decoder/Texture/Coder/RGB_ATC_UByte.cs | 80 - .../Decoder/Texture/Coder/RGB_ETC1_UByte.cs | 72 - .../Decoder/Texture/Coder/RGB_ETC2_UByte.cs | 69 - .../Texture/Coder/RGB_PVRTCI_2BPP_UByte.cs | 44 - .../Texture/Coder/RGB_PVRTCI_4BPP_UByte.cs | 44 - .../Decoder/Texture/Coder/RG_EAC_UByte.cs | 70 - .../Decoder/Texture/Coder/R_EAC_UByte.cs | 70 - .../OpenGLES/IOpenGLES20CompressedTexture.cs | 11 - .../OpenGLES/IOpenGLES20Texture.cs | 15 - .../Xbox360D3D9/D3DFORMAT.cs | 472 --- .../Xbox360D3D9/GPUENDIAN.cs | 25 - .../Xbox360D3D9/GPUNUMFORMAT.cs | 17 - .../Xbox360D3D9/GPUSIGN.cs | 28 - .../Xbox360D3D9/GPUSWIZZLE.cs | 49 - .../Xbox360D3D9/GPUTEXTUREFORMAT.cs | 265 -- .../Xbox360D3D9/IXbox360D3D9Texture.cs | 10 - .../Decoder/Texture/IPitchableTextureCoder.cs | 31 - .../Graphics/Decoder/Texture/ITextureCoder.cs | 29 - .../Decoder/Texture/Shared/ATCCoder.cs | 146 - .../Decoder/Texture/Shared/BCCoder.cs | 1462 --------- .../Decoder/Texture/Shared/ChannelHelper.cs | 19 - .../Decoder/Texture/Shared/EACCoder.cs | 295 -- .../Decoder/Texture/Shared/ETCCoder.cs | 1906 ------------ .../Texture/Shared/PS4TextureHelper.cs | 58 - .../Decoder/Texture/Shared/PVRTCCoder.cs | 2622 ----------------- .../Decoder/Texture/Shared/PVRTexLibHelper.cs | 135 - .../Graphics/Decoder/Texture/TextureCoder.cs | 32 - .../Decoder/Texture/TextureSettings.cs | 17 - .../Graphics/Decoder/ThrowHelper.cs | 15 - .../Graphics/Decoder/YFColor.cs | 104 - .../Graphics/KTX/KtxBitFiddling.cs | 24 - .../Graphics/KTX/KtxCommon.cs | 492 ---- .../Graphics/KTX/KtxCreator.cs | 29 - .../Graphics/KTX/KtxErrors.cs | 20 - .../Graphics/KTX/KtxHeader.cs | 440 --- .../Graphics/KTX/KtxLoader.cs | 63 - .../Graphics/KTX/KtxStructure.cs | 31 - .../Graphics/KTX/KtxTextureData.cs | 164 -- .../Graphics/KTX/KtxValidators.cs | 261 -- .../Graphics/KTX/KtxWriter.cs | 69 - .../Graphics/KTX/MetadataValue.cs | 82 - .../Graphics/KTX/VersionInfo.cs | 20 - .../Graphics/KTX2/KTX2_HELPER.cs | 226 +- .../Graphics/PVR/ATC_Master.cs | 43 + .../Graphics/PVR/CTX1Decoder.cs | 99 + .../Graphics/PVR/PVR_Helper.cs | 34 + .../Graphics/PVR/PVR_Master.cs | 98 + .../TelltaleTextureTool/Main/D3DTX_Master.cs | 334 ++- .../TelltaleTextureTool/Main/DDS_Master.cs | 107 +- .../TelltaleTextureTool/Main/KTX2_Master.cs | 1 + .../TelltaleTextureTool/Main/Main_Shared.cs | 2 +- .../Main/Texture_Master.cs | 232 +- .../FileTypes/D3DTX/Enums/T3PlatformType.cs | 27 +- .../FileTypes/D3DTX/Enums/T3SurfaceFormat.cs | 137 +- .../D3DTX/Enums/T3TextureAlphaMode.cs | 8 +- .../FileTypes/D3DTX/Enums/T3TextureLayout.cs | 17 +- .../Telltale/FileTypes/D3DTX/ID3DTX.cs | 12 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV1.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV10.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV11.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV12.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV13.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV2.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV3.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV4.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV5.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV6.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV7.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV8.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_CLV9.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV1.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV10.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV11.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV12.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV13.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV2.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV3.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV4.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV5.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV6.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV7.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV8.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_LV9.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_V3.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_V4.cs | 2 +- .../FileTypes/D3DTX/Versions/D3DTX_V5.cs | 4 +- .../FileTypes/D3DTX/Versions/D3DTX_V6.cs | 4 +- .../FileTypes/D3DTX/Versions/D3DTX_V7.cs | 4 +- .../FileTypes/D3DTX/Versions/D3DTX_V8.cs | 6 +- .../FileTypes/D3DTX/Versions/D3DTX_V9.cs | 10 +- .../TelltaleTextureTool.csproj | 24 +- .../TelltaleTextureTool/Utilities/Decoders.cs | 7 - .../Utilities/FormatDecoders/AtcDecoder.cs | 191 -- .../Utilities/FormatDecoders/PVRTCDecoder.cs | 554 ---- .../Utilities/PlatformDecoders/PS4Decode.cs | 1003 ------- .../Utilities/PlatformDecoders/XboxDecoder.cs | 32 +- .../Utilities/TextureTypes.cs | 3 +- 128 files changed, 2624 insertions(+), 14719 deletions(-) create mode 100644 TelltaleTextureTool/TelltaleTextureTool/GUI/ImageAdvancedOptions.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/BitHelper.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/ArrayPoolBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/ArraySegmentBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/IBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/IDisposableBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/MemoryBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/MemoryPoolBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/NativeBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Bitmap/RefBitmap.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/L8_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_ATC_Explicit_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_ATC_Interpolated_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_BC1_PS4_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_ETC2_EAC_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_ETC2_Punchthrough_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_PVRTCII_2BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_PVRTCII_4BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_PVRTCI_2BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGBA_PVRTCI_4BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGB_ATC_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGB_ETC1_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGB_ETC2_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGB_PVRTCI_2BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RGB_PVRTCI_4BPP_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/RG_EAC_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Coder/R_EAC_UByte.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/OpenGLES/IOpenGLES20CompressedTexture.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/OpenGLES/IOpenGLES20Texture.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/D3DFORMAT.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/GPUENDIAN.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/GPUNUMFORMAT.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/GPUSIGN.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/GPUSWIZZLE.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/GPUTEXTUREFORMAT.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IGraphicsAPITexture/Xbox360D3D9/IXbox360D3D9Texture.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/IPitchableTextureCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/ITextureCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/ATCCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/BCCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/ChannelHelper.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/EACCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/ETCCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/PS4TextureHelper.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/PVRTCCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/Shared/PVRTexLibHelper.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/TextureCoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/Texture/TextureSettings.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/ThrowHelper.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/Decoder/YFColor.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxBitFiddling.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxCommon.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxCreator.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxErrors.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxHeader.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxLoader.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxStructure.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxTextureData.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxValidators.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/KtxWriter.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/MetadataValue.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/KTX/VersionInfo.cs create mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/PVR/ATC_Master.cs create mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/PVR/CTX1Decoder.cs create mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/PVR/PVR_Helper.cs create mode 100644 TelltaleTextureTool/TelltaleTextureTool/Graphics/PVR/PVR_Master.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Utilities/Decoders.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Utilities/FormatDecoders/AtcDecoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Utilities/FormatDecoders/PVRTCDecoder.cs delete mode 100644 TelltaleTextureTool/TelltaleTextureTool/Utilities/PlatformDecoders/PS4Decode.cs diff --git a/TelltaleTextureTool/TelltaleTextureTool/App.axaml b/TelltaleTextureTool/TelltaleTextureTool/App.axaml index 8379afa..3c5e1c4 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/App.axaml +++ b/TelltaleTextureTool/TelltaleTextureTool/App.axaml @@ -8,9 +8,9 @@ RequestedThemeVariant="Dark"> - #424242 - #303030 - #3e3f52 + #333333 + #454545 + #1f2124 @@ -23,10 +23,6 @@ Value="{DynamicResource ButtonColor}" /> - - - - - + + + diff --git a/TelltaleTextureTool/TelltaleTextureTool/Converter.cs b/TelltaleTextureTool/TelltaleTextureTool/Converter.cs index af07248..4c3ea3a 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/Converter.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/Converter.cs @@ -18,7 +18,6 @@ namespace TelltaleTextureTool; public static class Converter { - public static string[] GetExtension(TextureType textureType) { return textureType switch @@ -32,6 +31,7 @@ public static string[] GetExtension(TextureType textureType) TextureType.BMP => [Main_Shared.bmpExtension], TextureType.TIFF => [Main_Shared.tiffExtension, Main_Shared.tifExtension], TextureType.TGA => [Main_Shared.tgaExtension], + TextureType.HDR => [Main_Shared.hdrExtension], _ => throw new InvalidEnumArgumentException("Invalid texture type."), }; } @@ -439,21 +439,21 @@ public static void ConvertTextureFromDdsToOthers(string? sourceFilePath, string //ConvertOptions if (d3dtxTextureType == T3TextureType.eTxBumpmap || d3dtxTextureType == T3TextureType.eTxNormalMap) { - DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, DDS_DirectXTexNet.DDSConversionMode.SWIZZLE_ABGR); + // DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, ImageEffect.SWIZZLE_ABGR); } else if (d3dtxTextureType == T3TextureType.eTxNormalXYMap) { - DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, DDS_DirectXTexNet.DDSConversionMode.RESTORE_Z); + // DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, ImageEffect.RESTORE_Z); } else { - DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, DDS_DirectXTexNet.DDSConversionMode.DEFAULT); + // DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, ImageEffect.DEFAULT); } } // If we didn't find a JSON file, use default conversion. else { - DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, DDS_DirectXTexNet.DDSConversionMode.DEFAULT); + // DDS_DirectXTexNet.SaveDDSToWIC(sourceFilePath, destinationDirectory, newTextureType, ImageEffect.DEFAULT); throw new FileNotFoundException( "No .json file was found for the file.\nDefaulting to classic conversion."); } diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageAdvancedOptions.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageAdvancedOptions.cs new file mode 100644 index 0000000..e007285 --- /dev/null +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageAdvancedOptions.cs @@ -0,0 +1,135 @@ +using System.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; +using TelltaleTextureTool.DirectX; +using TelltaleTextureTool.Main; +using TelltaleTextureTool.TelltaleEnums; +using TelltaleTextureTool.ViewModels; + +namespace TelltaleTextureTool; + +public partial class ImageAdvancedOptions : ObservableObject +{ + + //Private telltale games + [ObservableProperty] + private D3DTXVersion _d3dtxVersion; + + [ObservableProperty] + private TextureType _textureType; + + [ObservableProperty] + private bool _enableMips = false; + + [ObservableProperty] + private bool _autoGenerateMips = false; + + [ObservableProperty] + private bool _manualGenerateMips = false; + + [ObservableProperty] + private uint _setMips = 1; + + [ObservableProperty] + private bool _compression; + + [ObservableProperty] + private bool _enableAutomaticCompression; + + [ObservableProperty] + private bool _isAutomaticCompression; + + [ObservableProperty] + private bool _isManualCompression; + + [ObservableProperty] + private T3SurfaceFormat _format; + + [ObservableProperty] + private bool _enableNormalMap; + + [ObservableProperty] + private bool _encodeDDSHeader; + + [ObservableProperty] + private bool _filterValues; + + [ObservableProperty] + private bool _enableWrapU; + + [ObservableProperty] + private bool _enableWrapV; + + [ObservableProperty] + private bool _enableEditing; + + [ObservableProperty] + private bool _enableSwizzle; + + [ObservableProperty] + private bool _isSwizzle; + + [ObservableProperty] + private bool _isDeswizzle; + + [ObservableProperty] + private T3PlatformType _platformType = T3PlatformType.ePlatform_All; + + [ObservableProperty] + private bool _enableAlpha; + + [ObservableProperty] + private T3TextureAlphaMode _alphaFormat; + + [ObservableProperty] + private ImageEffect _imageEffect; + + // Store a reference to MainViewModel + private readonly MainViewModel _mainViewModel; + + public ImageAdvancedOptions(MainViewModel mainViewModel) + { + _mainViewModel = mainViewModel; + } + + public ImageAdvancedOptions(ImageAdvancedOptions imageAdvancedOptions) + { + _d3dtxVersion = imageAdvancedOptions._d3dtxVersion; + _textureType = imageAdvancedOptions._textureType; + _enableMips = imageAdvancedOptions._enableMips; + _autoGenerateMips = imageAdvancedOptions._autoGenerateMips; + _manualGenerateMips = imageAdvancedOptions._manualGenerateMips; + _setMips = imageAdvancedOptions._setMips; + _compression = imageAdvancedOptions._compression; + _enableAutomaticCompression = imageAdvancedOptions._enableAutomaticCompression; + _isAutomaticCompression = imageAdvancedOptions._isAutomaticCompression; + _isManualCompression = imageAdvancedOptions._isManualCompression; + _format = imageAdvancedOptions._format; + _enableNormalMap = imageAdvancedOptions._enableNormalMap; + _encodeDDSHeader = imageAdvancedOptions._encodeDDSHeader; + _filterValues = imageAdvancedOptions._filterValues; + _enableWrapU = imageAdvancedOptions._enableWrapU; + _enableWrapV = imageAdvancedOptions._enableWrapV; + _enableEditing = imageAdvancedOptions._enableEditing; + _enableSwizzle = imageAdvancedOptions._enableSwizzle; + _isSwizzle = imageAdvancedOptions._isSwizzle; + _isDeswizzle = imageAdvancedOptions._isDeswizzle; + _platformType = imageAdvancedOptions._platformType; + _enableAlpha = imageAdvancedOptions._enableAlpha; + _alphaFormat = imageAdvancedOptions._alphaFormat; + _imageEffect = imageAdvancedOptions._imageEffect; + _mainViewModel = imageAdvancedOptions._mainViewModel; + } + + public ImageAdvancedOptions() { } + + // Override OnPropertyChanged to trigger the MainViewModel's command + protected override void OnPropertyChanged(PropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + + // Trigger the command in MainViewModel + + _mainViewModel.UpdateBitmapCommand.Execute(null); + } + +} diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageBitmap.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageBitmap.cs index 18a1831..5b87ace 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageBitmap.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageBitmap.cs @@ -17,42 +17,6 @@ namespace TelltaleTextureTool.Utilities; public static class ImageUtilities { - /// - /// Checks if the image from a file path is transparent. - /// - /// - /// - public static bool IsImageOpaque(string imageFilePath) - { - var image = SixLabors.ImageSharp.Image.Load(imageFilePath); - - bool hasAlpha = false; - - image.ProcessPixelRows(pixelAccessor => - { - for (int y = 0; y < pixelAccessor.Height; y++) - { - Span pixelRow = pixelAccessor.GetRowSpan(y); - - for (int x = 0; x < pixelRow.Length; x++) - { - if (pixelRow[x].A != 255) - { - hasAlpha = true; - break; - } - } - - if (hasAlpha) - { - break; - } - } - }); - - return hasAlpha; - } - /// /// Checks if the loaded image has any transparent pixels. /// diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageData.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageData.cs index 0a5215e..19218b0 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageData.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageData.cs @@ -2,96 +2,87 @@ using System.IO; using TelltaleTextureTool.DirectX; using TelltaleTextureTool.Main; -using TelltaleTextureTool.Utilities; -using SixLabors.ImageSharp.PixelFormats; -using static Ktx.Ktx2; using TelltaleTextureTool.Telltale.FileTypes.D3DTX; using Avalonia.Media.Imaging; -using BitMiracle.LibTiff.Classic; -using Pfim; using SkiaSharp; using System.Runtime.InteropServices; -using Avalonia.Platform; -using Avalonia; namespace TelltaleTextureTool; public class ImageData { - public ImageProperties ImageProperties { get; set; } - public Bitmap ImageBitmap { get; set; } - public DDS DDSImage { get; set; } - - private uint Mip { get; set; } - private uint Face { get; set; } + public ImageProperties ImageProperties { get; set; } = new ImageProperties(); + public Texture DDSImage { get; set; } = new Texture(); public uint MaxMip { get; set; } public uint MaxFace { get; set; } - private string CurrentFilePath { get; set; } + private string CurrentFilePath { get; set; } = string.Empty; + private bool IsSamePath { get; set; } private TextureType CurrentTextureType { get; set; } - private D3DTXVersion CurrentD3DTXVersion { get; set; } + private D3DTXVersion CurrentD3DTXVersion { get; set; } - public ImageData(string filePath, TextureType textureType, D3DTXVersion d3DTXVersion = D3DTXVersion.DEFAULT, uint mip = 0, uint face = 0) + public void Initialize(string filePath, TextureType textureType, D3DTXVersion d3DTXVersion = D3DTXVersion.DEFAULT, uint mip = 0, uint face = 0) { - Mip = mip; - Face = face; + IsSamePath = CurrentFilePath == filePath; + + if (!IsSamePath && CurrentFilePath != string.Empty) + { + if (CurrentTextureType != TextureType.Unknown) + { + DDSImage.Release(); + } + } + CurrentFilePath = filePath; CurrentTextureType = textureType; CurrentD3DTXVersion = d3DTXVersion; - GetImageData(out Bitmap imageBitmap, out ImageProperties imageProperties); + GetImageData(out ImageProperties imageProperties); - ImageBitmap = imageBitmap; ImageProperties = imageProperties; } - public void SetImageData(string filePath, TextureType textureType, D3DTXVersion d3DTXVersion = D3DTXVersion.DEFAULT, uint mip = 0, uint face = 0) + /// + /// Applies the effects to the image. + /// + /// + public void ApplyEffects(ImageAdvancedOptions options) { - Mip = mip; - Face = face; - CurrentFilePath = filePath; - CurrentTextureType = textureType; - CurrentD3DTXVersion = d3DTXVersion; + DDSImage.ChangePreviewImage(options); - GetImageData(out Bitmap imageBitmap, out ImageProperties imageProperties); + DDSImage.GetBounds(out uint maxMip, out uint maxFace); + MaxMip = maxMip; + MaxFace = maxFace; - ImageBitmap = imageBitmap; - ImageProperties = imageProperties; + ImageProperties = DDS_DirectXTexNet.GetDDSProperties(CurrentFilePath, DDSImage.Metadata); } - private void GetImageData(out Bitmap bitmap, out ImageProperties imageProperties) + private void GetImageData(out ImageProperties imageProperties) { switch (CurrentTextureType) { + case TextureType.DDS: case TextureType.BMP: case TextureType.PNG: case TextureType.TGA: case TextureType.JPEG: - GetImageDataFromOthers(out bitmap, out imageProperties); - break; case TextureType.TIFF: - GetImageDataFromTIFF(out bitmap, out imageProperties); - break; - case TextureType.DDS: - GetImageDataFromDDS(out bitmap, out imageProperties); + case TextureType.HDR: + GetImageDataFromCommon(out imageProperties); break; case TextureType.D3DTX: - GetImageDataFromD3DTX(CurrentD3DTXVersion, out bitmap, out imageProperties); - break; - case TextureType.KTX: - case TextureType.KTX2: - GetImageDataFromInvalid(out bitmap, out imageProperties); + GetImageDataFromD3DTX(CurrentD3DTXVersion, out imageProperties); break; default: - GetImageDataFromInvalid(out bitmap, out imageProperties); + GetImageDataFromInvalid(out imageProperties); break; } } - private void GetImageDataFromD3DTX(D3DTXVersion d3DTXVersion, out Bitmap bitmap, out ImageProperties imageProperties) + private void GetImageDataFromD3DTX(D3DTXVersion d3DTXVersion, out ImageProperties imageProperties) { var d3dtx = new D3DTX_Master(); d3dtx.ReadD3DTXFile(CurrentFilePath, d3DTXVersion); @@ -102,53 +93,93 @@ private void GetImageDataFromD3DTX(D3DTXVersion d3DTXVersion, out Bitmap bitmap, imageProperties = new ImageProperties() { Name = metadata.TextureName, - SurfaceFormat = d3dtx.GetStringFormat(), + SurfaceFormat = d3dtx.GetSurfaceFormat(), Width = metadata.Width.ToString(), Height = metadata.Height.ToString(), HasAlpha = d3dtx.GetHasAlpha(), - ChannelCount = d3dtx.GetChannelCount(), - MipMapCount = metadata.MipLevels.ToString() + // ChannelCount = d3dtx.GetChannelCount(), + MipMapCount = metadata.MipLevels.ToString(), + TextureLayout = metadata.Dimension.ToString(), + AlphaMode = metadata.AlphaMode.ToString(), + ArraySize = metadata.ArraySize.ToString(), }; - // Initialize image bitmap - DDS_Master ddsFile = new(d3dtx); - var array = ddsFile.GetData(d3dtx); - - DDSImage = new DDS(array); + if (!IsSamePath) + { + // Initialize image bitmap + DDS_Master ddsFile = new(d3dtx); + var array = ddsFile.GetData(d3dtx); - bitmap = ConvertDdsToBitmap(Mip, Face); + DDSImage = new DirectX.Texture(array, TextureType.D3DTX); + } } - private void GetImageDataFromDDS(out Bitmap bitmap, out ImageProperties imageProperties) + /// + /// Gets the pre-defined advanced options for the image. + /// + /// + /// + public ImageAdvancedOptions GetImageAdvancedOptions(ImageAdvancedOptions options) { - // if (filePath != currentFilePath) - // { + if (CurrentTextureType != TextureType.D3DTX) + { + return options; + } - // currentFilePath = filePath; - // } - Console.WriteLine("I AM IN DDSImage"); - DDSImage = new DDS(CurrentFilePath); + var d3dtx = new D3DTX_Master(); + d3dtx.ReadD3DTXFile(CurrentFilePath, CurrentD3DTXVersion); - bitmap = ConvertDdsToBitmap(Mip, Face); + // Initialize image properties + D3DTXMetadata metadata = d3dtx.GetMetadata(); + + if (D3DTX_Master.IsPlatformIncompatibleWithDDS(metadata.Platform)) + { + // options.EnableSwizzle = true; + // options.IsDeswizzle = true; + // options.PlatformType = metadata.Platform; + } + + return options; + } + + private void GetImageDataFromCommon(out ImageProperties imageProperties) + { + if (!IsSamePath) + { + DDSImage = new Texture(CurrentFilePath, CurrentTextureType); + } imageProperties = DDS_DirectXTexNet.GetDDSProperties(CurrentFilePath, DDSImage.Metadata); } /// - /// Converts .dds files to a bitmap. This is only used in the image preview. + /// Converts the data from the scratch image to a bitmap. /// - /// The dds image from DirectXTexNet. - /// The png bitmap from .dds. - private Bitmap ConvertDdsToBitmap(uint mip, uint face) + /// + /// + /// The bitmap from the mip and face. + public Bitmap GetBitmapFromScratchImage(uint mip = 0, uint face = 0) { - Console.WriteLine("I AM IN DDS TO BITMAP"); - DDSImage.GetData(mip, face, out ulong width, out ulong height, out ulong pitch, out ulong length, out byte[] pixelData); - Console.WriteLine("I AM IN DDS TO BITMAP GETDATA"); + if (TextureType.Unknown == CurrentTextureType) + { + return new Bitmap(MemoryStream.Null); + } + DDSImage.GetBounds(out uint maxMip, out uint maxFace); - Console.WriteLine("I AM IN DDS TO BITMAP GetBounds"); MaxMip = maxMip; MaxFace = maxFace; - + + if (mip > maxMip) + { + mip = MaxMip; + } + if (face > maxFace) + { + face = MaxFace; + } + + DDSImage.GetData(mip, face, out ulong width, out ulong height, out ulong pitch, out ulong length, out byte[] pixelData); + // Converts the data into writeableBitmap. (TODO Insert a link to the code) var imageInfo = new SKImageInfo((int)width, (int)height, SKColorType.Rgba8888); var handle = GCHandle.Alloc(pixelData, GCHandleType.Pinned); @@ -171,266 +202,8 @@ private Bitmap ConvertDdsToBitmap(uint mip, uint face) return new Bitmap(memoryStream); } - private static Bitmap GetDDSBitmap(IImage image) + private static void GetImageDataFromInvalid(out ImageProperties imageProperties) { - var pixels = image.DataLen; - //get the data - var newData = image.Data; - var newDataLen = image.DataLen; - var stride = image.Stride; - - // Get the color type - SKColorType colorType; - switch (image.Format) - { - case ImageFormat.Rgb8: - colorType = SKColorType.Gray8; - break; - case ImageFormat.R5g5b5: // Pfim doesn't support L16 and L8A8 formats. Images with these formats will be incorrectly interpreted as R5G5B5. - pixels /= 2; - newDataLen = pixels * 2; - newData = new byte[newDataLen]; - for (var i = 0; i < pixels; i++) - { - ushort pixelData = BitConverter.ToUInt16(image.Data, i * 2); - byte r = (byte)((pixelData & 0x7C00) >> 10); // Red component - byte g = (byte)((pixelData & 0x03E0) >> 5); // Green component - byte b = (byte)(pixelData & 0x001F); // Blue component - ushort rgb565 = (ushort)((r << 11) | (g << 5) | b); // Combine components into RGB565 format - byte[] rgb565Bytes = BitConverter.GetBytes(rgb565); - newData[i * 2] = rgb565Bytes[0]; - newData[i * 2 + 1] = rgb565Bytes[1]; - } - stride = image.Width * 2; - colorType = SKColorType.Rgb565; - break; - case ImageFormat.R5g5b5a1: - pixels /= 2; // Each pixel is 2 bytes in R5G5B5A1 format - newDataLen = pixels * 4; // Each pixel will be 4 bytes in RGBA8888 format - newData = new byte[newDataLen]; - for (var i = 0; i < pixels; i++) - { - ushort pixelData = BitConverter.ToUInt16(image.Data, i * 2); - byte r = (byte)((pixelData & 0x7C00) >> 10); // Red component - byte g = (byte)((pixelData & 0x03E0) >> 5); // Green component - byte b = (byte)(pixelData & 0x001F); // Blue component - newData[i * 4] = r; - newData[i * 4 + 1] = g; - newData[i * 4 + 2] = b; - newData[i * 4 + 3] = 255; // Alpha channel set to 255 (fully opaque) - } - stride = image.Width * 4; - colorType = SKColorType.Rgba8888; - break; - case ImageFormat.R5g6b5: - colorType = SKColorType.Rgb565; - break; - case ImageFormat.Rgba16: - colorType = SKColorType.Argb4444; - break; - case ImageFormat.Rgb24: - // Skia has no 24bit pixels, so we upscale to 32bit - pixels = image.DataLen / 3; - newDataLen = pixels * 4; - newData = new byte[newDataLen]; - for (var i = 0; i < pixels; i++) - { - newData[i * 4] = image.Data[i * 3]; - newData[i * 4 + 1] = image.Data[i * 3 + 1]; - newData[i * 4 + 2] = image.Data[i * 3 + 2]; - newData[i * 4 + 3] = 255; - } - - stride = image.Width * 4; - colorType = SKColorType.Bgra8888; - break; - case ImageFormat.Rgba32: - colorType = SKColorType.Bgra8888; - break; - default: - throw new ArgumentException($"Skia unable to interpret pfim format: {image.Format}"); - } - - // Converts the data into writeableBitmap. (TODO Insert a link to the code) - var imageInfo = new SKImageInfo(image.Width, image.Height, colorType); - var handle = GCHandle.Alloc(newData, GCHandleType.Pinned); - var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(newData, 0); - using var data = SKData.Create(ptr, newDataLen, (_, _) => handle.Free()); - using var skImage = SKImage.FromPixels(imageInfo, data, stride); - using var bitmap = SKBitmap.FromImage(skImage); - - // Create a memory stream to hold the PNG data - var memoryStream = new MemoryStream(); - - // Encode the bitmap to PNG and write it to the memory stream - var wstream = new SKManagedWStream(memoryStream); - - var success = bitmap.Encode(wstream, SKEncodedImageFormat.Png, 95); - Console.WriteLine(success ? "Image converted successfully" : "Image conversion failed"); - - memoryStream.Position = 0; - - return new Bitmap(memoryStream); - } - - private void GetImageDataFromOthers(out Bitmap bitmap, out ImageProperties imageProperties) - { - // Load the image using SkiaSharp - using (var skBitmap = SKBitmap.Decode(CurrentFilePath)) - { - // Create a memory stream to hold the image data - using (var ms = new MemoryStream()) - { - // Encode the SKBitmap to a PNG and write to the memory stream - skBitmap.Encode(ms, SKEncodedImageFormat.Png, 100); - ms.Seek(0, SeekOrigin.Begin); // Rewind the stream to the beginning - - // Create an Avalonia Bitmap from the memory stream - bitmap = new Bitmap(ms); - } - - string hasAlphaString = skBitmap.Info.IsOpaque ? "False" : "True"; - - imageProperties = new ImageProperties() - { - Name = Path.GetFileNameWithoutExtension(CurrentFilePath), - Extension = Path.GetExtension(CurrentFilePath), - SurfaceFormat = skBitmap.ColorType.ToString(), - ChannelCount = (skBitmap.BytesPerPixel * 8).ToString(), - Height = skBitmap.Height.ToString(), - Width = skBitmap.Width.ToString(), - HasAlpha = hasAlphaString, - MipMapCount = "N/A" // SkiaSharp does not provide mipmap count directly - }; - } - } - - private void GetImageDataFromTIFF(out Bitmap bitmap, out ImageProperties imageProperties) - { - bitmap = ConvertTiffToBitmap(); - - var imageInfo = SixLabors.ImageSharp.Image.Identify(CurrentFilePath); - var image = SixLabors.ImageSharp.Image.Load(CurrentFilePath); - - bool hasAlpha = ImageUtilities.IsImageOpaque(image); - string hasAlphaString = hasAlpha ? "True" : "False"; - - imageProperties = new ImageProperties() - { - Name = Path.GetFileNameWithoutExtension(CurrentFilePath), - Extension = Path.GetExtension(CurrentFilePath), - SurfaceFormat = imageInfo.Metadata.DecodedImageFormat.Name, - ChannelCount = (imageInfo.PixelType.BitsPerPixel / 8).ToString(), - Height = imageInfo.Height.ToString(), - Width = imageInfo.Width.ToString(), - HasAlpha = hasAlphaString, - MipMapCount = "N/A" - }; - } - - private void GetImageDataFromInvalid(out Bitmap? bitmap, out ImageProperties imageProperties) - { - bitmap = null; - - imageProperties = new ImageProperties() - { - Name = "", - SurfaceFormat = "", - ChannelCount = "", - Height = "", - Width = "", - MipMapCount = "", - HasAlpha = "" - }; - } - - /// - /// Converts .tiff to a bitmap. This is only used in the image preview. - /// - /// - /// - private Bitmap ConvertTiffToBitmap() - { - byte[] fileBytes = File.ReadAllBytes(CurrentFilePath); - Stream tiffStream = new MemoryStream(fileBytes); - // open a TIFF stored in the stream - using var tifImg = Tiff.ClientOpen("in-memory", "r", tiffStream, new TiffStream()); - // read the dimensions - var width = tifImg.GetField(TiffTag.IMAGEWIDTH)[0].ToInt(); - var height = tifImg.GetField(TiffTag.IMAGELENGTH)[0].ToInt(); - - //Experimentation, ignore this - //var smth = tifImg.GetField(TiffTag.COMPRESSION)[0].ToInt(); - - // create the bitmap - var bitmap = new SKBitmap(); - var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, - SKColorSpace.CreateSrgb()); - - // create the buffer that will hold the pixels - var raster = new int[width * height]; - - // get a pointer to the buffer, and give it to the bitmap - var ptr = GCHandle.Alloc(raster, GCHandleType.Pinned); - bitmap.InstallPixels(info, ptr.AddrOfPinnedObject(), info.RowBytes); - - - // read the image into the memory buffer - if (!tifImg.ReadRGBAImageOriented(width, height, raster, - BitMiracle.LibTiff.Classic.Orientation.TOPLEFT)) - { - // not a valid TIF image. - return null; - } - - // swap the red and blue because SkiaSharp may differ from the tiff - if (SKImageInfo.PlatformColorType == SKColorType.Bgra8888) - { - SKSwizzle.SwapRedBlue(ptr.AddrOfPinnedObject(), raster.Length); - } - - var writeableBitmap = new WriteableBitmap(new PixelSize(width, height), new Vector(96, 96), - PixelFormat.Bgra8888); - - using var lockedBitmap = writeableBitmap.Lock(); - // Copy the SKBitmap pixel data to the Avalonia WriteableBitmap - Marshal.Copy(bitmap.Bytes, 0, lockedBitmap.Address, bitmap.Bytes.Length); - - return writeableBitmap; - } - - // /// - // /// Gets the properties of the selected .dds file - // /// - // /// - // private static ImageProperties GetKtx2Properties(string ddsFilePath) - // { - // Texture texture = KTX2_Bindings.GetKTX2Texture(ddsFilePath); - - // return new ImageProperties - // { - // Name = Path.GetFileNameWithoutExtension(ddsFilePath), - // Extension = ".ktx2", - // Height = texture.BaseHeight.ToString(), - // Width = texture.BaseWidth.ToString(), - // SurfaceFormat = texture.VkFormat.ToString(), - // HasAlpha = KTX2_HELPER.HasAlpha(texture.VkFormat) ? "True" : "False", - // //ChannelCount = Helper.GetDataFormatDescriptor(texture.VkFormat).DescriptorBlockSize.ToString(), - // MipMapCount = texture.NumLevels.ToString() - // }; - // } - - public static ImageProperties GetImagePropertiesFromInvalid() - { - return new ImageProperties() - { - Name = "", - SurfaceFormat = "", - ChannelCount = "", - Height = "", - Width = "", - MipMapCount = "", - HasAlpha = "" - }; + imageProperties = new(); } } \ No newline at end of file diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs index af1617b..747c398 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs @@ -7,14 +7,15 @@ public class ImageProperties : ObservableObject /// /// Image properties that are displayed on the panel. /// - public string? Name { get; set; } - public string? Extension { get; set; } - public string? Width { get; set; } - public string? Height { get; set; } - public string? SurfaceFormat { get; set; } - public string? HasAlpha { get; set; } - public string? BitsPerPixel { get; set; } - public string? ChannelCount { get; set; } - public string? MipMapCount { get; set; } - public string? TextureLayout { get; set; } -} \ No newline at end of file + public string Name { get; set; } = string.Empty; + public string Extension { get; set; } = string.Empty; + public string Width { get; set; } = string.Empty; + public string Height { get; set; } = string.Empty; + public string SurfaceFormat { get; set; } = string.Empty; + public string BitsPerPixel { get; set; } = string.Empty; + public string MipMapCount { get; set; } = string.Empty; + public string ArraySize { get; set; } = string.Empty; + public string HasAlpha { get; set; } = string.Empty; + public string AlphaMode { get; set; } = string.Empty; + public string TextureLayout { get; set; } = string.Empty; +} diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs index 7cdf87d..0a4ec65 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs @@ -21,11 +21,57 @@ using TelltaleTextureTool.DirectX; using TelltaleTextureTool.Telltale.TTArch; using Avalonia.Data; -using Hexa.NET.DirectXTex; -using Pfim; +using System.ComponentModel; +using Avalonia.Data.Converters; +using System.ComponentModel.DataAnnotations; +using System.Globalization; +using System.Reflection; +using TelltaleTextureTool.TelltaleEnums; + namespace TelltaleTextureTool.ViewModels; +public class EnumDisplayNameConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + return string.Empty; + + // Get the field in the enum type that matches the current enum value + FieldInfo field = value.GetType().GetField(value.ToString()); + + // Get the Display attribute if present + DisplayAttribute attribute = field?.GetCustomAttributes(false) + .OfType() + .FirstOrDefault(); + + // Return the name if available, otherwise fall back to the enum value's name + return attribute?.Name ?? value.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + // Reverse the conversion if needed + if (value is string stringValue) + { + foreach (var field in targetType.GetFields()) + { + var attribute = field.GetCustomAttributes(false) + .OfType() + .FirstOrDefault(); + + if (attribute?.Name == stringValue || field.Name == stringValue) + { + return Enum.Parse(targetType, field.Name); + } + } + } + + throw new InvalidOperationException("Cannot convert back."); + } +} + public partial class MainViewModel : ViewModelBase { #region MEMBERS @@ -34,8 +80,11 @@ public partial class MainViewModel : ViewModelBase [ new FormatItemViewModel { Name = "DDS", ItemStatus = true }, new FormatItemViewModel { Name = "PNG", ItemStatus = false }, - new FormatItemViewModel { Name = "KTX", ItemStatus = false }, - new FormatItemViewModel { Name = "KTX2", ItemStatus = false } + new FormatItemViewModel { Name = "JPEG", ItemStatus = false }, + new FormatItemViewModel { Name = "BMP", ItemStatus = false }, + new FormatItemViewModel { Name = "TIFF", ItemStatus = false }, + new FormatItemViewModel { Name = "TGA", ItemStatus = false }, + new FormatItemViewModel { Name = "HDR", ItemStatus = false }, ]; private readonly ObservableCollection _ddsTypes = @@ -45,7 +94,8 @@ public partial class MainViewModel : ViewModelBase new FormatItemViewModel { Name = "JPEG", ItemStatus = true }, new FormatItemViewModel { Name = "BMP", ItemStatus = true }, new FormatItemViewModel { Name = "TIFF", ItemStatus = true }, - new FormatItemViewModel { Name = "TGA", ItemStatus = false } + new FormatItemViewModel { Name = "TGA", ItemStatus = false }, + new FormatItemViewModel { Name = "HDR", ItemStatus = true }, ]; private readonly ObservableCollection _ktxTypes = @@ -108,14 +158,14 @@ public partial class MainViewModel : ViewModelBase private int mode = 0; - private readonly List _allTypes = [".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".d3dtx", ".dds", ".ktx", ".ktx2", ".tga"]; + private readonly List _allTypes = [".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".d3dtx", ".dds", ".hdr", ".tga"]; // No idea if this is correct public static FilePickerFileType AllowedTypes { get; } = new("All Supported Types") { - Patterns = ["*.png", "*.jpg", "*.jpeg", "*.bmp", "*.tif", "*.tiff", "*.d3dtx", "*.dds", "*.ktx", "*.ktx2", "*.tga", "*.json"], + Patterns = ["*.png", "*.jpg", "*.jpeg", "*.bmp", "*.tif", "*.tiff", "*.d3dtx", "*.dds", "*.hdr", "*.tga", "*.json"], AppleUniformTypeIdentifiers = ["public.image"], - MimeTypes = ["image/png", "image/jpeg", "image/bmp", "image/tiff", "image/tga", "image/vnd.ms-dds", "image/vnd.ms-d3dtx", "image/vnd.ms-ktx", "image/vnd.ms-ktx2"] + MimeTypes = ["image/png", "image/jpeg", "image/bmp", "image/tiff", "image/tga", "image/hdr", "image/vnd.ms-dds", "image/vnd.ms-d3dtx", "image/vnd.ms-ktx2"] }; // No idea if this is correct @@ -128,10 +178,8 @@ public partial class MainViewModel : ViewModelBase private ObservableCollection? _columns = new ObservableCollection() { new DataGridTextColumn(){Header = "1", Binding = new Binding("KrnListValueId"){ Source = _workingDirectoryFiles }}, - }; - private readonly MainManager mainManager = MainManager.GetInstance(); private readonly Uri _assetsUri = new("avares://TelltaleTextureTool/Assets/"); private static readonly string ErrorSvgFilename = "error.svg"; @@ -139,10 +187,27 @@ public partial class MainViewModel : ViewModelBase #endregion #region UI PROPERTIES + public ImageEffect[] ImageConversionModes { get; } = [ + ImageEffect.DEFAULT, + ImageEffect.SWIZZLE_ABGR, + ImageEffect.RESTORE_Z, + ImageEffect.REMOVE_Z]; + + public T3PlatformType[] SwizzlePlatforms { get; } = [ + T3PlatformType.ePlatform_All, + T3PlatformType.ePlatform_Xbox, + T3PlatformType.ePlatform_XBOne, + T3PlatformType.ePlatform_PS3, + T3PlatformType.ePlatform_PS4, + T3PlatformType.ePlatform_NX, + T3PlatformType.ePlatform_Wii, + T3PlatformType.ePlatform_WiiU, + ]; [ObservableProperty] private ImageProperties _imageProperties; + [ObservableProperty] private ImageAdvancedOptions _imageAdvancedOptions; + [ObservableProperty] private bool _isChecked = false; [ObservableProperty] private FormatItemViewModel _selectedFormat; - [ObservableProperty] private FormatItemViewModel _selectedVersionConvertOption; [ObservableProperty] private ObservableCollection _formatsList = []; [ObservableProperty] private ObservableCollection _versionConvertOptionsList = []; @@ -157,6 +222,7 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private int _selectedComboboxIndex; [ObservableProperty] private int _selectedLegacyTitleIndex; + [ObservableProperty] private uint _maxMipCountButton; [ObservableProperty] private string? _imageNamePreview; [ObservableProperty] private IImage? _imagePreview; [ObservableProperty] private string _fileText = string.Empty; @@ -164,16 +230,17 @@ public partial class MainViewModel : ViewModelBase [ObservableProperty] private bool _returnDirectoryButtonStatus; [ObservableProperty] private bool _refreshDirectoryButtonStatus; [ObservableProperty] private bool _chooseOutputDirectoryCheckboxStatus; - [ObservableProperty] private string _debugInfo = string.Empty; + [ObservableProperty] private bool _isMipSliderVisible; + [ObservableProperty] private bool _isFaceSliderVisible; - [ObservableProperty][NotifyCanExecuteChangedFor("PreviewImageCommand")] private uint _mipValue; - [ObservableProperty][NotifyCanExecuteChangedFor("PreviewImageCommand")] private uint _faceValue; + [ObservableProperty] private string _debugInfo = string.Empty; + [ObservableProperty] private uint _mipValue; + [ObservableProperty] private uint _faceValue; [ObservableProperty] private uint _maxMipCount; [ObservableProperty] private uint _maxFaceCount; [ObservableProperty] private static ObservableCollection _workingDirectoryFiles = []; [ObservableProperty] private ObservableCollection _archiveFiles = []; - - [ObservableProperty] private ImageData _imageData; + [ObservableProperty] private ImageData _imageData = new ImageData(); [ObservableProperty] [NotifyCanExecuteChangedFor("ResetPanAndZoomCommand")] @@ -204,6 +271,7 @@ public MainViewModel() }; VersionConvertOptionsList = _versionConvertOptions; SelectedVersionConvertOption = VersionConvertOptionsList[0]; + ImageAdvancedOptions = new ImageAdvancedOptions(this); } #region MAIN MENU BUTTONS ACTIONS @@ -617,8 +685,8 @@ public async Task ConvertButton_Click() if (types.Length == 2) { - oldTextureType = GetTextureTypeFromExtension(types[0]); - newTextureType = GetTextureTypeFromExtension(types[1]); + oldTextureType = GetTextureTypeFromItem(types[0].Trim()); + newTextureType = GetTextureTypeFromItem(types[1].Trim()); if (!ChooseOutputDirectoryCheckboxStatus) { @@ -667,6 +735,7 @@ private static TextureType GetTextureTypeFromItem(string newTextureType) "KTX" => TextureType.KTX, "KTX2" => TextureType.KTX2, "TGA" => TextureType.TGA, + "HDR" => TextureType.HDR, _ => TextureType.Unknown }; } @@ -855,6 +924,7 @@ private void ChangeComboBoxItemsByItemExtension(string itemExtension) { ".tga", _otherTypes }, { ".tif", _otherTypes }, { ".tiff", _otherTypes }, + { ".hdr", _otherTypes }, {"", _folderTypes} }; @@ -983,7 +1053,7 @@ private void ResetUIElements() DebugButtonStatus = false; ChooseOutputDirectoryCheckboxStatus = false; - ImageProperties = ImageData.GetImagePropertiesFromInvalid(); + ImageProperties = new ImageProperties(); ImagePreview = new SvgImage() { Source = SvgSource.Load(ErrorSvgFilename, _assetsUri) @@ -1012,33 +1082,89 @@ public async Task PreviewImage() var filePath = workingDirectoryFile.FilePath; var extension = Path.GetExtension(filePath).ToLowerInvariant(); + if (Directory.Exists(filePath)) + { + return; + } + ImageNamePreview = workingDirectoryFile.FileName + workingDirectoryFile.FileType; TextureType textureType = TextureType.Unknown; if (extension != string.Empty) textureType = GetTextureTypeFromItem(extension.ToUpperInvariant().Remove(0, 1)); - ImageData imageData = new(filePath, textureType, GetD3DTXConversionType(), MipValue, FaceValue); + ImageData.Initialize(filePath, textureType, GetD3DTXConversionType()); - MaxMipCount = imageData.MaxMip; - MaxFaceCount = imageData.MaxFace; + ImageAdvancedOptions = ImageData.GetImageAdvancedOptions(ImageAdvancedOptions); - ImageProperties = imageData.ImageProperties; + if (textureType != TextureType.Unknown) + { + ImageData.ApplyEffects(ImageAdvancedOptions); + } + + await DebugButton_Click(); + + MaxMipCount = ImageData.MaxMip; + MaxFaceCount = ImageData.MaxFace; + + IsFaceSliderVisible = MaxFaceCount != 0; + IsMipSliderVisible = MaxMipCount != 0; + MaxMipCountButton = ImageData.DDSImage.GetMaxMipLevels(); - if (imageData.ImageBitmap == null) + ImageProperties = ImageData.ImageProperties; + + if (textureType != TextureType.Unknown) + { + ImagePreview = ImageData.GetBitmapFromScratchImage(MipValue, FaceValue); + } + else { - ImagePreview = new SvgImage() + ImagePreview = new SvgImage { Source = SvgSource.Load(ErrorSvgFilename, _assetsUri) }; } - else + } + catch (Exception ex) + { + Console.WriteLine(ex.StackTrace); + await HandleImagePreviewErrorAsync(ex); + } + } + + [RelayCommand] + public async Task UpdateBitmap() + { + try + { + if (DataGridSelectedItem == null) + return; + + var workingDirectoryFile = DataGridSelectedItem; + var filePath = workingDirectoryFile.FilePath; + var extension = Path.GetExtension(filePath).ToLowerInvariant(); + + TextureType textureType = TextureType.Unknown; + if (extension != string.Empty) + textureType = GetTextureTypeFromItem(extension.ToUpperInvariant().Remove(0, 1)); + + if (textureType == TextureType.Unknown) { - ImagePreview = imageData.ImageBitmap; + return; } - await DebugButton_Click(); + ImageData.ApplyEffects(ImageAdvancedOptions); + + MaxMipCount = ImageData.MaxMip; + MaxFaceCount = ImageData.MaxFace; + + IsFaceSliderVisible = MaxFaceCount != 0; + IsMipSliderVisible = MaxMipCount != 0; + + ImageProperties = ImageData.ImageProperties; + + ImagePreview = ImageData.GetBitmapFromScratchImage(MipValue, FaceValue); } catch (Exception ex) { @@ -1047,6 +1173,19 @@ public async Task PreviewImage() } } + protected override async void OnPropertyChanged(PropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + if (e.PropertyName == nameof(MipValue) || e.PropertyName == nameof(FaceValue)) + { + ImagePreview = ImageData.GetBitmapFromScratchImage(MipValue, FaceValue); + } + if (e.PropertyName == nameof(ImageAdvancedOptions)) + { + await UpdateBitmap(); + } + } + private Task OpenFileExplorer(string path) { MainManager.OpenFileExplorer(path); diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml b/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml index 6f6ba85..dcd083e 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml @@ -4,7 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:TelltaleTextureTool.ViewModels" mc:Ignorable="d" - d:DesignWidth="3000" + d:DesignWidth="1500" d:DesignHeight="1000" x:Class="TelltaleTextureTool.Views.MainView" xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity" @@ -16,13 +16,15 @@ to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> + + + + Height="38"> @@ -31,8 +33,8 @@ VerticalAlignment="Top" HorizontalAlignment="Center"> + Width="24" + Height="24" /> - @@ -51,8 +52,8 @@ VerticalAlignment="Top" HorizontalAlignment="Center"> + Width="24" + Height="24" /> - @@ -70,8 +70,8 @@ VerticalAlignment="Top" HorizontalAlignment="Center"> + Width="24" + Height="24" /> - @@ -89,8 +88,8 @@ VerticalAlignment="Top" HorizontalAlignment="Center"> + Width="24" + Height="24" /> - @@ -109,8 +107,8 @@ VerticalAlignment="Top" HorizontalAlignment="Center"> + Width="24" + Height="24" /> - + + Width="24" + Height="24 " /> - - + @@ -173,94 +171,94 @@ Background="{DynamicResource PanelSplitterColor}" /> -