diff --git a/TelltaleTextureTool/TelltaleTextureTool/App.axaml b/TelltaleTextureTool/TelltaleTextureTool/App.axaml index 134f304..8379afa 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/App.axaml +++ b/TelltaleTextureTool/TelltaleTextureTool/App.axaml @@ -17,15 +17,175 @@ + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (filePath); - - bool hasAlpha = ImageUtilities.IsImageOpaque(image); - string hasAlphaString = hasAlpha ? "True" : "False"; - - imageProperties = new ImageProperties() + // Load the image using SkiaSharp + using (var skBitmap = SKBitmap.Decode(filePath)) { - Name = Path.GetFileNameWithoutExtension(filePath), - Extension = Path.GetExtension(filePath), - CompressionType = imageInfo.Metadata.DecodedImageFormat.Name, - ChannelCount = (imageInfo.PixelType.BitsPerPixel / 8).ToString(), - Height = imageInfo.Height.ToString(), - Width = imageInfo.Width.ToString(), - HasAlpha = hasAlphaString, - MipMapCount = "N/A" - }; + // 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 ? "True" : "False"; + + imageProperties = new ImageProperties() + { + Name = Path.GetFileNameWithoutExtension(filePath), + Extension = Path.GetExtension(filePath), + 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 GetImageDataFromD3DTX(string filePath, D3DTXVersion d3DTXVersion, out Bitmap bitmap, out ImageProperties imageProperties) @@ -94,7 +103,7 @@ private void GetImageDataFromD3DTX(string filePath, D3DTXVersion d3DTXVersion, o imageProperties = new ImageProperties() { Name = metadata.TextureName, - CompressionType = d3dtx.GetStringFormat(), + SurfaceFormat = d3dtx.GetStringFormat(), Width = metadata.Width.ToString(), Height = metadata.Height.ToString(), HasAlpha = d3dtx.GetHasAlpha(), @@ -131,7 +140,7 @@ private void GetImageDataFromTIFF(string filePath, out Bitmap bitmap, out ImageP { Name = Path.GetFileNameWithoutExtension(filePath), Extension = Path.GetExtension(filePath), - CompressionType = imageInfo.Metadata.DecodedImageFormat.Name, + SurfaceFormat = imageInfo.Metadata.DecodedImageFormat.Name, ChannelCount = (imageInfo.PixelType.BitsPerPixel / 8).ToString(), Height = imageInfo.Height.ToString(), Width = imageInfo.Width.ToString(), @@ -147,7 +156,7 @@ private void GetImageDataFromInvalid(out Bitmap? bitmap, out ImageProperties ima imageProperties = new ImageProperties() { Name = "", - CompressionType = "", + SurfaceFormat = "", ChannelCount = "", Height = "", Width = "", @@ -303,7 +312,6 @@ private static Bitmap GetDDSBitmap(IImage image) 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); @@ -339,7 +347,7 @@ private static ImageProperties GetKtx2Properties(string ddsFilePath) Extension = ".ktx2", Height = texture.BaseHeight.ToString(), Width = texture.BaseWidth.ToString(), - CompressionType = texture.VkFormat.ToString(), + SurfaceFormat = texture.VkFormat.ToString(), HasAlpha = KTX2_HELPER.HasAlpha(texture.VkFormat) ? "True" : "False", //ChannelCount = Helper.GetDataFormatDescriptor(texture.VkFormat).DescriptorBlockSize.ToString(), MipMapCount = texture.NumLevels.ToString() @@ -351,7 +359,7 @@ public static ImageProperties GetImagePropertiesFromInvalid() return new ImageProperties() { Name = "", - CompressionType = "", + SurfaceFormat = "", ChannelCount = "", Height = "", Width = "", diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs index 3eaafbe..af1617b 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ImageProperties.cs @@ -11,7 +11,7 @@ public class ImageProperties : ObservableObject public string? Extension { get; set; } public string? Width { get; set; } public string? Height { get; set; } - public string? CompressionType { get; set; } + public string? SurfaceFormat { get; set; } public string? HasAlpha { get; set; } public string? BitsPerPixel { get; set; } public string? ChannelCount { get; set; } diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs index 68f26cf..0b9bf4f 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/ViewModels/MainViewModel.cs @@ -85,6 +85,21 @@ public partial class MainViewModel : ViewModelBase new FormatItemViewModel { Name = "Legacy Version 9", ItemStatus = true}, new FormatItemViewModel { Name = "Legacy Version 10", ItemStatus = true}, new FormatItemViewModel { Name = "Legacy Version 11", ItemStatus = true}, + new FormatItemViewModel { Name = "Legacy Version 12", ItemStatus = true}, + new FormatItemViewModel { Name = "Legacy Version 13", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 1", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 2", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 3", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 4", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 5", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 6", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 7", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 8", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 9", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 10", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 11", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 12", ItemStatus = true}, + new FormatItemViewModel { Name = "Console Legacy Version 13", ItemStatus = true}, ]; private readonly List _allTypes = [".png", ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".d3dtx", ".dds", ".ktx", ".ktx2", ".tga"]; @@ -177,6 +192,7 @@ public MainViewModel() #region MAIN MENU BUTTONS ACTIONS // Open Directory Command + [RelayCommand] public async Task OpenDirectoryButton_Click() { try @@ -202,7 +218,8 @@ public async Task OpenDirectoryButton_Click() } } - public async void SaveFileButton_Click() + [RelayCommand] + public async Task SaveFileButton_Click() { try { @@ -244,7 +261,8 @@ public async void SaveFileButton_Click() } } - public async void AddFilesButton_Click() + [RelayCommand] + public async Task AddFilesButton_Click() { try { @@ -287,6 +305,7 @@ public async void AddFilesButton_Click() } // Delete Command + [RelayCommand] public async Task DeleteFileButton_Click() { var workingDirectoryFile = @@ -330,6 +349,7 @@ public async Task DeleteFileButton_Click() } } + [RelayCommand] public void HelpButton_Click() { mainManager.OpenAppHelp(); @@ -352,7 +372,8 @@ public void AboutButton_Click() #region CONTEXT MENU ACTIONS - public async void ContextMenuAddFilesCommand() + [RelayCommand] + public async Task ContextMenuAddFilesCommand() { try { @@ -396,7 +417,8 @@ public async void ContextMenuAddFilesCommand() await UpdateUiAsync(); } - public async void ContextMenuOpenFileCommand() + [RelayCommand] + public async Task ContextMenuOpenFileCommand() { try { @@ -419,7 +441,8 @@ public async void ContextMenuOpenFileCommand() } } - public async void ContextMenuOpenFolderCommand() + [RelayCommand] + public async Task ContextMenuOpenFolderCommand() { try { @@ -620,6 +643,21 @@ private D3DTXVersion GetD3DTXConversionType() "Legacy Version 9" => D3DTXVersion.LV9, "Legacy Version 10" => D3DTXVersion.LV10, "Legacy Version 11" => D3DTXVersion.LV11, + "Legacy Version 12" => D3DTXVersion.LV12, + "Legacy Version 13" => D3DTXVersion.LV13, + "Console Legacy Version 1" => D3DTXVersion.CLV1, + "Console Legacy Version 2" => D3DTXVersion.CLV2, + "Console Legacy Version 3" => D3DTXVersion.CLV3, + "Console Legacy Version 4" => D3DTXVersion.CLV4, + "Console Legacy Version 5" => D3DTXVersion.CLV5, + "Console Legacy Version 6" => D3DTXVersion.CLV6, + "Console Legacy Version 7" => D3DTXVersion.CLV7, + "Console Legacy Version 8" => D3DTXVersion.CLV8, + "Console Legacy Version 9" => D3DTXVersion.CLV9, + "Console Legacy Version 10" => D3DTXVersion.CLV10, + "Console Legacy Version 11" => D3DTXVersion.CLV11, + "Console Legacy Version 12" => D3DTXVersion.CLV12, + "Console Legacy Version 13" => D3DTXVersion.CLV13, _ => D3DTXVersion.DEFAULT }; } @@ -718,6 +756,7 @@ private async Task UpdateUiAsync() #region SMALL MENU BUTTON ACTIONS + [RelayCommand] public async Task ReturnDirectory_Click() { try @@ -737,6 +776,7 @@ public async Task ReturnDirectory_Click() } } + [RelayCommand] public async Task ContextMenuRefreshDirectoryCommand() { await RefreshDirectoryButton_Click(); diff --git a/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml b/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml index 0d54c90..c089d1a 100644 --- a/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml +++ b/TelltaleTextureTool/TelltaleTextureTool/GUI/Views/MainView.axaml @@ -4,8 +4,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:TelltaleTextureTool.ViewModels" mc:Ignorable="d" - d:DesignWidth="1000" - d:DesignHeight="550" + d:DesignWidth="3000" + d:DesignHeight="1000" x:Class="TelltaleTextureTool.Views.MainView" xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity" xmlns:paz="using:Avalonia.Controls.PanAndZoom" @@ -16,560 +16,571 @@ to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -